Dizwell Informatics

News from Nowhere

Running Crontab jobs as Root

Solaris won’t, by default, let you modify the supplied crontab file for the root user. Try it, and you’ll get this sort of thing:

root@bach:~# export EDITOR=nano
root@bach:~# crontab -e
Warning - Invalid account: 'root' not allowed to execute cronjobs
The crontab file was not changed.

You can edit the crontab file as much as you like after receiving that message, but it won’t be saved and certainly won’t make any operational difference to your crontab entries.

So if you need to cron something as root, how do you do it? By editing /etc/shadow. When you open that file up in the text editor of your choice, you will see something like this:

[and so on]

The zero you see on the end of the ‘root:’ line is the culprit. Change that to 1, like so:


Save that and try to alter your root crontab now and you should find that no more warnings are displayed. More importantly, you’ll find alterations to your root crontab now persist.

The alteration to /etc/shadow is actually telling the system that the root password has been changed 1 day after January 1st 1970. Which isn’t, of course, true: I can’t log on to my Solaris boxen as root at all, because he’s not a ‘real’ user, just a role I can assume thanks to sudo. The edit, however, makes it seem as if root is real -and at that point, he’s allowed to have a crontab file he can edit. Hence subsequent crontab -e‘s work as expected.