Another cron job problem - Raspberry Pi Forums
i have script (checkroute.sh), use set special route if not exist , if specific wifi ssid connected.
works fine when run pi command line shown here: wanted set cron run every minute ran crontab -e add following: not getting output @ checkroute.txt file.
listing of zero-length file: wrong here? expected printed lines stdout added txt file, nothing seems happen.
clarity here script containg echo commands:
works fine when run pi command line shown here:
code: select all
pi@rpi2-jessie2:~ $ ./checkroute.sh checking wifi routing connected auriga-ap! main route exists. check vpn route... vpn route exists! nothing needs done.
code: select all
* * * * * /home/pi/checkroute.sh >> /home/pi/checkroute.txt
listing of zero-length file:
code: select all
-rw-r--r-- 1 pi pi 0 feb 7 17:48 checkroute.txt
clarity here script containg echo commands:
code: select all
# ---- script used check wifi routing vpn network 10.0.0.x ----- #configuration values: apname="auriga-ap" wifigw=192.168.137.1 quiet=off while [ $# -gt 0 ] case "$1" in -q) quiet=on;; esac shift done [ "$quiet" == "off" ] && echo "checking wifi routing" if iwgetid | grep $apname > /dev/null [ "$quiet" == "off" ] && echo "connected $apname!" if route -n | grep "ug 303 0 0 wlan0" > /dev/null # extract wlan0 gateway address wifigw=$(route -n | grep "0.0.0.0 ug" | grep wlan0) wifigw=${wifigw:16:15} wifigw=$(echo $wifigw | xargs) [ "$quiet" == "off" ] && echo "main route exists. check vpn route..." if route -n | grep wlan0 | grep 10.0.0.0 > /dev/null [ "$quiet" == "off" ] && echo "vpn route exists! nothing needs done." exit 0 fi [ "$quiet" == "off" ] && echo "vpn route not exist! try create it..." if sudo route add -net 10.0.0.0 netmask 255.255.255.0 gw $wifigw > /dev/null [ "$quiet" == "off" ] && echo "succeeded add vpn route!" exit 0 fi [ "$quiet" == "off" ] && echo "failed add vpn route!" exit 1 else [ "$quiet" == "off" ] && echo "no wlan connected anymore!" exit 2 fi else [ "$quiet" == "off" ] && echo "no connection $apname, no need anything" exit 0 fi
with option normal output messages go file. need send error message somewhere too. or send same file normal output goes file descriptor (output channel) 1. error output goes file descriptor 2. "2>&1" means "send output file descriptor 2 file descriptor 1"
code: select all
* * * * * /home/pi/checkroute.sh >> /home/pi/checkroute.txt 2>>/home/pi/checkroute.err
code: select all
* * * * * /home/pi/checkroute.sh >> /home/pi/checkroute.txt 2>&1
raspberrypi
Comments
Post a Comment