here is the task:
Add a cron job to the system-wide cron table. This cron job should run as a user called Mary, on the 15th day of every month, at 4 AM
why is this not acceptable ?
sudo vim /etc/crontab
0 4 15 * * mary find /home/mary/ -type d -empty -delete
why this one is acceptable ?
sudo crontab -e
Add the cron job entry at the end of the file:
0 4 15 * * su - mary -c ‘find /home/mary/ -type d -empty -delete’
Save and exit the editor
This is confusing !!!
There are two compound fields in a crontab entry
- The schedule, e.g.
0 4 15 * *
- The command to be run, which is everything else after the schedule.
The command to be run is as if you had entered it at the terminal prompt:
$ mary find /home/mary/ -type d -empty -delete
Try pasting that directly to the command prompt ad see how far you get! You will get something like
Command ‘mary’ not found
…which is what the cron daemon will see, and it will put that in its log file.
On the other hand, run this command (as root)
$ su - mary -c ‘find /home/mary/ -type d -empty -delete’
and the command will execute.
System cron table is executed in the context of the root user, therefore if you want to execute a command in the context of another user, you must use su
1 Like
Thank you for your feedback. But I think the system-wide crontable is /etc/crontab:
So even this approach now should work:
Sudo vim /etc/crontab
0 4 15 * * root su - mary -c ‘find /home/mary/ -type d -empty -delete’
Ok I get it now
system crontab is as per this.
If you’ve followed at as per that post and the question is marked wrong then there may be a bug in the grader. Check it again and report back please.