I'm trying to use cron to automate my system updates. You can see my crontab, commands, and resulting errors below.
When I run upgrades.sh as root, the script runs fine. When cron runs it, apt-get -y update
runs no problem, but aptitude -y safe-upgrade
fails. I'm guessing this error: debconf: (This frontend requires a controlling tty.)
is because there is a kernel update which in turn updates grub, which requires my explicitly saying it's okay to overwrite /boot/grub/menu.lst
. But I don't understand the path errors. And I'd like the updates that don't require my supervision to go through.
I have read through this question and it's as yet unaccepted solution of unattended-upgrades
, and I may end up using it, but why can't I use cron? Seems like it should be really simple, and more linuxy.
Crontab
root@daedalus:~/bin# crontab -l
# m h dom mon dow command
45 06 * * * ~/bin/upgrades.sh
upgrades.sh
root@daedalus:~/bin# cat upgrades.sh
#!/bin/bash
/usr/bin/apt-get -y update
/usr/bin/aptitude -y safe-upgrade
Errors
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:
Fetched 37.6MB in 4min 23s (143kB/s)
dpkg: warning: 'ldconfig' not found on PATH.
dpkg: warning: 'start-stop-daemon' not found on PATH.
dpkg: warning: 'update-rc.d' not found on PATH.
dpkg: 3 expected program(s) not found on PATH.
NB: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin.
E: Sub-process /usr/bin/dpkg returned an error code (2)
A package failed to install. Trying to recover:
dpkg: warning: 'ldconfig' not found on PATH.
dpkg: warning: 'start-stop-daemon' not found on PATH.
dpkg: warning: 'update-rc.d' not found on PATH.
dpkg: 3 expected program(s) not found on PATH.
NB: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin.
Reading package lists...
Building dependency tree...
Reading state information...
Reading extended state information...
Initializing package states...
Writing extended state information...
PATH=...
in a file, e.g.~/.env
, and source it from every script you write using. ~/.env
near the top of the script. Then if you change yourPATH
you only have to edit one file. 2) If you put it incrontab
, it means you don't have to edit all your cron scripts, but you will have two places to edit if you want to change yourPATH
(e.g.~/.bashrc
andcrontab
). Which is better is up to you. – Mikel Jan 29 '11 at 01:32cron
source code say what it is. In theory it could have been to force a consistent environment so you could copy a crontab from one user to another, but onlyPATH
gets changed, so that can't be the reason. – Mikel Jan 29 '11 at 01:58