Hi all. I have a bash script that I can call from the command line that works perfectly. I also have crontab (same user) call it every 5 minutes to make sure the network is up and connected. It fails most of the time, but works once in a while. This is very perplexing, and I have become frustrated trying to tweak it in order to get it working so I don't have to babysit the machine. I wrote the script because I have a usb wireless dongle that intermittently disconnects. (Please don't address the dongle issue, it's been death by a thousand cuts already and it still won't stop disconnecting.) This script would be a fine solution if it would work from crontab (automatically) as it does from the command line. I know the script passes through both legs of the if-else loop, because the logfile has the right entries. It just seems that when called from crontab, it acts like the nmcli commands aren't there at all. Here is the code:
Code: Select all
#!/bin/bash
#check wifi status for 'connected'
wifistate=$(nmcli nm status)
set $wifistate
if [ $8 = "connected" ]
then
echo $i "`date` : Interface up." >> /home/user/logfiles/wlan1check.log
else
echo `nmcli -t nm wifi off` >/dev/null
echo `nmcli -t nm wifi on` >/dev/null
wait 3
echo $i "`date` : Interface reset." >> /home/user/logfiles/wlan1check.log
fi
tail -1000 /home/user/logfiles/wlan1check.log > /home/user/logfiles/wlan1check.logtemp
mv /home/user/logfiles/wlan1check.logtemp /home/user/logfiles/wlan1check.log
exit 0
Anyone have any ideas why this script fails when crontab calls it, but succeeds when I call it from the command line?
Could it be some kind of permission issue between crontab and the network manager?
Thanks in advance.