Running Cron Job as Specific User in Ubuntu 12.10

My mailbox was flooded with notification emails due to wrong user permissions running the cron job. No good. It seems I don't know how to use crontab properly.Let's say we have a sample shell script, /home/foobar/foobar.sh and we want to run it as foobar user for every hour. Crontab line as follow:
0 */1 * * * foobar /home/foobar/foobar.sh

Apparently, there are three ways to run a cron job as specific user in Ubuntu.

1. Edit /etc/crontab and append above line to the file. Not recommended as it may lost due to package update or upgrade.

2. Create a file call foobar and put the above line in /etc/cron.d. Recommended as all users cron jobs are located in one location.

3. Create a crontab using that user. Workable but not located in centralized location like in (2).
$ sudo crontab -u foobar -e

No comments:

Post a Comment