Your script can be corrected and simplified like this:
#!/bin/sh
log=/tmp/vpn-check.log
{ date; ping -c3 192.168.17.27; } > $log
if grep -q '0 received' $log; then
/usr/sbin/pppd call home >>$log 2>&1
fi
Through our discussion in comments we confirmed that the script itself works, but pppd
doesn't, when running from cron
. This is because something must be different in an interactive shell like your terminal window, and in cron
. This kind of problem is very common by the way.
The first thing to do is try to remember what configuration is necessary for pppd
. I don't use it so I don't know. Maybe you need to set some environment variables? In which case most probably you set something in a startup file, like .bashrc
, which is usually not used in a non-interactive shell, and would explain why pppd
doesn't work.
The second thing is to check the logs of pppd
. If you cannot find the logs easily, look into its man
page, and it's configuration files, and try to find the logs, or how to make it log. Based on the logs, you should be able to find what is missing when running in cron
, and resolve your problem.