1

I just switched to an Ubuntu 14.04 server from an 11.04 server. In /var/spool/cron/crontabs/root I have the line:

* * * * * /root/arewerunning.sh > /root/appmon.log

arewerunning.sh looks like this:

#!/bin/sh

if P=$(pgrep aserver)
then
  echo  " "
else
  echo "aserver has stopped. System Will reboot"
sudo reboot now
fi

On the 11.04 server this was working. Whenever I killed aserver the system would reboot. But on 14.04 the command appears to be running but the system does not restart. cron.log looks like:

(root) CMD (/root/arewerunning.sh > /root/appmon.log)

when the process hasn't been killed and like:

(root) CMD (/root/arewerunning.sh > /root/appmon.log)
(CRON) info (No MTA installed, discarding output)

when the process has been killed. I know that the MTA line is because it is trying to email me and it can't, but that shouldn't prevent the reboot.

I have tried running the command outside of cron and it works just fine. I'm using a direct path so that shouldn't be a problem. I have also tried adding "sh" in front of the command. appmon.log isn't showing anything. I've tried putting other commands in the file and they work just fine.

  • i) why are you using sudo if the script is already running as root? ii) does reboot work on 14.04? Try it from the command line manually. If not, try shutdown -r now or systemctl reboot (assuming 14.04 had systemctl, I don't remember). Also, please clarify whether you see the aserver has stopped... message in your log. – terdon Sep 26 '16 at 17:08
0

I figured it out! The problem was a path issue for reboot. I had to put "sudo /sbin/reboot now" in arewerunning.sh. I had read about the path issues for other commands but didn't put two and two together that reboot was also a command whose path might have been tampered with.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.