LFCS_Mock_Exam3-Q2

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 !!! :upside_down_face:

There are two compound fields in a crontab entry

  1. The schedule, e.g. 0 4 15 * *
  2. 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.

The wording, or grader, for this question is still incorrect.
Not to mention the supposed solution is very unusual (su - mary -c in root’s user-crontab … ).

Question:

  • Add a cron job to the system-wide cron table
    (i.e. /etc/crontab, as defined in man 5 crontab)

Details:

  • Is cron job is scheduled correctly for user mary ?
    (i.e. user mary, not root executing a command via su - mary -c )

Solution:

  • Open the root crontab file: 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’
    ( ??? )

I’m inclined to agree with you, and have raised the issue in our bug base. Editing /etc/crontab is what you should do, and we’re asking you in effect to edit the file in /var/spool/cron/crontabs/root. Which is NOT the “system-wide” crontab.

I’m told we’ve fixed the issue. Thanks for raising it with us!