Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Time and date stamps in cron?

    General pfSense Questions
    2
    5
    2.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      clarknova
      last edited by

      I'm trying to create a cron job to periodically log the output of 'netstat -m' with a timestamp, but I'm not sure how to create the timestamp. So I'm thinking of a command something like this

      
      echo "$date $time `netstat -m` >> /var/log/netstat-m.log
      
      

      but I don't know how to produce current values for $date and $time. Help?

      Also, some tips on formatting the output would be good, like how to insert a line break after the output. Thanks.

      db

      1 Reply Last reply Reply Quote 0
      • jimpJ
        jimp Rebel Alliance Developer Netgate
        last edited by

        Make sure you use the full path to every command in a cron entry, and no need to involve echo:

        /bin/date >> /var/log/netstat-m.log; /usr/bin/netstat -m >> /var/log/netstat-m.log
        

        Remember: Upvote with the ๐Ÿ‘ button for any user/post you find to be helpful, informative, or deserving of recognition!

        Need help fast? Netgate Global Support!

        Do not Chat/PM for help!

        1 Reply Last reply Reply Quote 0
        • C
          clarknova
          last edited by

          Perfect. Thanks.

          db

          1 Reply Last reply Reply Quote 0
          • C
            clarknova
            last edited by

            One more thing, does that directory survive reboots?

            db

            1 Reply Last reply Reply Quote 0
            • jimpJ
              jimp Rebel Alliance Developer Netgate
              last edited by

              On a full install, yes. On nanobsd, no.

              Remember: Upvote with the ๐Ÿ‘ button for any user/post you find to be helpful, informative, or deserving of recognition!

              Need help fast? Netgate Global Support!

              Do not Chat/PM for help!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.