Quantcast
Viewing latest article 29
Browse Latest Browse All 48

Answer by Mange for Why crontab scripts are not working?

Writing to cron via "crontab -e" with the username argument in a line. I've seen examples of users (or sysadmins) writing their shell scripts and not understanding why they don't automate. The "user" argument exists in /etc/crontab, but not the user-defined files. so, for example, your personal file would be something like:

# m h dom mon dow command* * */2  *   *  /some/shell/script

whereas /etc/crontab would be:

# m h dom mon dow user   command* * */2  *   *  jdoe   /some/shell/script

So, why would you do the latter? Well, depending on how you want to set your permissions, this can become very convoluted. I've written scripts to automate tasks for users who don't understand the intricacies, or don't want to bother with the drudgery. By setting permissions to --x------, I can make the script executable without them being able to read (and perhaps accidentally change) it. However, I might want to run this command with several others from one file (thus making it easier to maintain) but make sure file output is assigned the right owner. Doing so (at least in Ubuntu 10.10) breaks on both the inability to read the file as well as execute, plus the afore-mentioned issue with putting periods in /etc/crontab (which, funnily enough, causes no error when going through crontab -e).

As an example, I've seen instances of sudo crontab -e used to run a script with root permissions, with a corresponding chown username file_output in the shell script. Sloppy, but it works. IMHO, The more graceful option is to put it in /etc/crontab with username declared and proper permissions, so file_output goes to the right place and owner.


Viewing latest article 29
Browse Latest Browse All 48

Trending Articles