Why does apt-get fail when automated with cron?

Solution 1:

Although your main problem has already been answered, it looks like you're getting debconf warnings because you're running apt-get without an interactive tty. To get rid of these messages, you can set this environment variable:

DEBIAN_FRONTEND=noninteractive

Solution 2:

The messages are telling you that your PATH environment variable is wrong.

Try adding

PATH=/usr/bin:/bin:/usr/sbin:/sbin

to the top of your crontab.

Or you could put the same PATH line as the second line of ~/bin/upgrades.sh. That way your test from the command line and your test from crontab should produce the same results.

Solution 3:

There is a community wiki page: Reason why crontab does not work. In this case, it seems as though the cause is cron's limited environment variables. Can you run this from a shell script in /etc/cron.daily?