You appear to have some "useless use of
sudo" in this script. That is, if you can run this successfully:
/sbin/ifconfig wlan0 down
Then you're probably already root, so you should be able to:
/sbin/iwconfig wlan0 essid "WLA_NETWORK"
There are a couple of things that could prevent your script in its current form from running:
sudo can be configured to require a valid tty (using the
requiretty configuration directive). If this flag is active you won't able to use
- You're using fully qualified paths for
ifconfig but not for
iwconfig. If this command isn't in the
PATH available when run via
sudo, it's not going to work.
Here are somethings you can do to fix it:
- Remove the use of
sudo. Either run the entire script via
sudo or just run it as
dhclient with fully qualified paths.
stderr from the script to a file so that you can inspect the output. Your crontab entry would look something like
* * * * * /path/to/your/script > /tmp/script.log 2>&1.
If your script is still having problems at this point, any errors logged in the output file show help point the way to a solution.