Why is Cron not running the enable wifi command?

I'm trying to use crontab to schedule the 'enable wifi' command: networksetup -setairportpower en0 on.

I've been entering this command in the required format in the cron file, eg.:

05 15 * * * networksetup -setairportpower en0 on

However, it isn't working. This command works when I use it normally, and I've used crontab to successfully run other commands. Why is the command not running as intended, and what should I do to fix it?


In addition to possible permissions problem, you might be having trouble because networksetup isn't in the default PATH for cron jobs. The default path for cron jobs includes just /bin and /usr/bin, but the networksetup executable is in /usr/sbin, so the command will not be found.

To prevent this problem, you can use an explicit full path for the command:

05 15 * * * /usr/sbin/networksetup -setairportpower en0 on

Another option is to adjust the PATH variable in the crontab file (before the command that depends on it), something like this:

PATH=/usr/bin:/bin:/usr/sbin:/sbin
05 15 * * * networksetup -setairportpower en0 on

Also, when troubleshooting cron jobs, it's often very helpful to capture errors and output from the jobs in some easily-accessible place, and then examine them to see what they indicate. You can capture them with a redirect, something like this:

05 15 * * * /usr/sbin/networksetup -setairportpower en0 on >>/tmp/cronjob.log 2>&1

...and then look at /tmp/cronjob.log after the job runs.