1

I have an unresolved problem with my vps falling off the network. There's no reply and the webhost have no idea, so I thought this bash script should work

#!/bin/sh
ping -c5 8.8.8.8
if [ $? -eq 0 ]; then
    echo "ok"
else
    reboot
fi

Runs every minute via cron

* * * * * /bin/sh /root/pingtest.sh

But it's not rebooting when the machine drops off the network - here we can see the syslog showing it losing connection (to the nfs in this case), and the pingtest runs shortly after, but isn't rebooting the machine.

May 18 08:58:01 tns CRON[9543]: (root) CMD (/bin/sh /root/pingtest.sh)
May 18 08:58:23 tns kernel: [316511.688142] nfs: server 188.166.172.XX not responding, timed out
May 18 08:59:00 tns kernel: [316548.720075] nfs: server 188.166.172.XX not responding, timed out
May 18 08:59:01 tns CRON[9549]: (root) CMD (/bin/sh /root/pingtest.sh)

What am I doing wrong? Thanks.

  • 1
    Probably reboot (usually /sbin/reboot) is not in cron's PATH – steeldriver May 18 '16 at 12:31
  • stackoverflow.com/questions/27452790/… I agree with the above answer, more help in the link here. – Javier Ochoa May 18 '16 at 12:38
  • Thanks @steeldriver and javier - of course, that makes sense. I've also added the path to ping, just in case! Thanks. – digitaltoast May 18 '16 at 14:37

Your Answer

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

Browse other questions tagged or ask your own question.