PDA

View Full Version : [ubuntu] how to write to log from shellscript just before restart?



vikka
July 8th, 2012, 12:34 PM
Hello,

I've setup some cronjobs(running sh scripts) on my ubuntu 12.04 server and one of them is a scheduled reboot, however if i try to write to a logfile in the same .sh file as my reboot script nothing seems to be written.

What i'd like to do is simply state uptime,date and then do the restart, something like:

#!/bin/sh
sudo date >> reboot.log
sudo uptime >> reboot.log
sudo shutdown -r 1

If i run this script outside a cronjob , i.e just directly then it does write the reboot.log file, but if i run the script from the cronjob it only restarts and does not write the date,uptime to a file.

Any idea why?
Thanks.

Cheesemill
July 8th, 2012, 03:30 PM
Try using the full paths for date, uptime and reboot.log

vikka
July 8th, 2012, 06:38 PM
Try using the full paths for date, uptime and reboot.log

Thanks, that solved my issue.