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

    Log time and date on each pfsense start

    Scheduled Pinned Locked Moved General pfSense Questions
    4 Posts 2 Posters 2.0k Views
    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.
    • 8
      80286
      last edited by

      I have pfsense running at a very remote location. We have a lot of power outages there. I want to implement a script that will log time and date each time pfsense starts.

      What I want is a log file on pfsense hard drive that I can print out and see when pfsense was rebooted.

      I want something like this:

      2009-11-15.01:05:00 Started OK
      2009-12-19.02:15:12 Started OK
      2010-01-25.11:05:00 Started OK
      

      If I put this script into Cron will it work? I wrote this based on another script, so it's probably wrong.

      minute 3
      hour *
      mday *
      month *
      wday *
      who root
      command echo `date +%Y-%m-%d.%H:%M:%S` "Started OK" >> /root/systemstarted.log
      

      Thanks in advance.

      1 Reply Last reply Reply Quote 0
      • ?
        Guest
        last edited by

        Your solution will eventually cause a log file to fill up the hard drive (depending on how often you have failures).  A better solution would be a monitoring system like zabbix or nagios.  If, however, you want to cause the script to run at startup, you would want to modify the rc.startup script in /etc.  This modification will not survive upgrades, so again, a dedicated monitoring solution is better.

        Incidentally, if you are suffering catastrophic power outages, there's a good chance you'll end up with a damaged file system on your hard drive.  Consider using embedded if you aren't already.

        1 Reply Last reply Reply Quote 0
        • 8
          80286
          last edited by

          This is a "volunteer" kind of place and I don't have money (and time) to spend on embedded systems/diesel generators/Zabbix monitoring servers, etc, etc… If it gets corrupted then I will print them a log of power failures and let them fix their power grid. Thanks for advice, but I need scripting help.

          If I understood correctly from another forum, I need to place a script in /usr/local/etc/rc.d/
          so that it will run once during each pfsense startup.

          So far my script looks like this:

          #!/bin/sh
          
          # Log file
          LOGFILE=/root/systemstarted.log
          #=====================================================================
          
          echo `date +%Y-%m-%d.%H:%M:%S` "Started OK" >> $LOGFILE
          
          exit
          

          Looking good? Will it automatically execute from that folder, or do I need to add it somewhere?

          At the end I would like to have something like this:

          2009-11-15.01:05:00 Started OK
          2009-12-19.02:15:12 Started OK
          2010-01-25.11:05:00 Started OK
          

          Any help greatly appreciated. Thanks in advance.

          1 Reply Last reply Reply Quote 0
          • 8
            80286
            last edited by

            WOW!!! I just tried my script on my secondary pfsense and it seems to work:

            2010-05-18.19:59:55 Started OK
            

            :o ;D 8) :D

            However, if you see any mistakes please let me know.

            EDIT: Do I need "exit" command at the end?

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