I feel like I have tried everything, my search history is about 20 pages deep on google trying to fix this and nothing works. Basically I have a script that checks if my tun0 interface exists, and if it is missing, the computer will restart. Here's the code:
#!/bin/bash
. /etc/profile
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
if echo `ifconfig` | grep -q "tun0"
then echo ""
else
reboot
fi
The script itself runs fine if I invoke it at a terminal using its path:
/scripts/vpnrestart1.sh
I've added this at the top of crontab -e:
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
My cron task looks like this:
* * * * * /scripts/vpnrestart1.sh
Permissions are all fine on the script itself and it can be executed without using sudo. As I mentioned, it runs from the terminal just fine and works as designed. But if I put it in cron and remove the tun0 interface, nothing ever happens.
reboot
works when run from thatcron
? Why don't you use the init system to manage this VPN?/etc/profile
, not/etc.profile
?ifconfig | grep
without the echo (not that it helps with the cron, either)