Search code examples
unixcronraspberry-pi

Wifi-connect works in bash but not in crontab


I use wifi-connect to configure my Raspberry Pi in unknown WLAN Networks.

wifi-connect works when I execute it via command line once the system booted, but when I put it into sudo crontab -e, it won't work. The cron logs show no errors. The autostart of my own scripts works.

My crontab: @reboot /usr/local/sbin/wifi-connect

Does someone have a hint for me why this does not work?


Solution

  • Usually this kind of issues (when things works in a terminal but not in crontab), since there is nothing tricky in the crontab entry (you are just calling a executable with no arguments) are due to timing issue. Likely the crontab entry get executed before the network stack is ready. To do a quick test add a delay to that execution prepending sleep 60; to your command, this will delay the execution of 1 minute, which should be enough. Anyway this is not a reliable solution, you will have to user a script o a service which actually check for the network stack.