Log time and date on each pfsense start
-
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.
-
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.
-
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.
-
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?