View Full Version : Crontab Logs With Dates
rbautch
07-04-2005, 11:16 PM
I run crond with the following command to log cron tasks:crond -l1 -L /var/spool/cron/logs/cronlogThis log seems pretty useless unless it appends a date and time to each task, which it doesn't. After a few hours of searching and googleing, the best I could come up with is to create log files for each task individually, with the time/date imbedded in the filename. I use a line in my crontab like this:15 9 * * * wget -O /dev/null "http://127.0.0.1/quit" >> /var/spool/cron/logs/TWP/TWPshutdownlog.$(date +\%Y\%m\%d_\%H:\%M)It works, but there's got to be an easier way. So, is there a level of logging or debugging that will put the dates in the cronlog? If not, can I modify the command above to just create a single log file with each instance of this crond task annotated with the date/time?
rbautch
07-09-2005, 12:40 PM
I learn a little more Linux every day. Finally fugured this out. This line in crontab seems to do the trick.
15 9 * * * wget -O /dev/null "http://127.0.0.1/quit"; echo "TWP stopped at `date`" >> /var/spool/cron/logs/TWP-restart-log
Jamie
10-28-2005, 12:28 PM
I learn a little more Linux every day. Finally fugured this out. This line in crontab seems to do the trick.
15 9 * * * wget -O /dev/null "http://127.0.0.1/quit"; echo "TWP stopped at `date`" >> /var/spool/cron/logs/TWP-restart-log
This is an old thread, but I think it is worth pointing out that this is a dangerous construct and can result in /dev/null getting wiped out. (http://www.dealdatabase.com/forum/showthread.php?t=45714&highlight=%2Fdev%2Fnull)
The issue is that wget deletes the output file if it gets an error (for example, if the url get's a 404 Not Found error). If you happen to have root mounted rw, you'll lose your /dev/null dev file and lots of things won't work correctly anymore.
I'd suggest using "-O -" and a shell redirect to /dev/null instead.
jasch
10-28-2005, 12:38 PM
Like this?
wget -O - "http://127.0.0.1/quit" >/dev/null
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.