crontab ifconfig outputting nothing

Solution 1:

try using the full path to the ifconfig executable in your script.

which ifconfig will give you the path.

I don't know what ipconfig does in ubuntu. :)

Solution 2:

In a cron job you probably want to redirect both stdout and stderr to the file. Change your script to this:

ifconfig &> /home/myname/foo

and you'll see the error message in your output file.

See All About Redirection in the Bash Programming How To for more info.

Solution 3:

  1. You probably need the full path to ipconfig in your script, or did you mean ifconfig? Either way, you should use the full path.
  2. You capture stdout in /home/myname/foo, but not stderr which probably gets the clue that you're missing here. Check your email for the output of the cronjob.

Solution 4:

crontab does not use user path variable.

You have to place command with full path to it. i.e. /sbin/ifconfig. Then this will be working.

Other way to solve this problem is to add PATH variable to your script and export it then your script will be able to use standard commands with out adding full path every time. You can check path typing echo $PATH in terminal.