LPIC-1 107.2: Scheduling jobs
A user crontab, one-off jobs with at, who may use cron, and the same job
as a systemd timer.
Before you start
The lab creates user alice (password Lab-Pass-1) and makes sure cron is
installed and running. at isn't set up: installing it and starting atd
is part of task 2. Tasks 1 and 2 need a few minutes of waiting.
Tasks
- As
alice, add a crontab entry that appends the output ofdateto~/date.logevery two minutes. Wait until the file has a line or two, then remove the entry. - Queue a job with
at now + 2 minutesthat writesfirstto/var/tmp/at-first. List it withatq, read it withat -c, and let it run. Then queue another that would writesecondto/var/tmp/at-second, write its job number to/root/lab-answers/2, and remove it withatrm. - Put
alicein/etc/cron.denyand trycrontab -eas her. Then create/etc/cron.allowwithout her name, and try again. - Turn the two-minute job into
datelog.serviceanddatelog.timer: the service runs asaliceand appendsdateto/home/alice/date.log, and the timer runs it withOnCalendar=*:0/2. Enable and start the timer, and watchsystemctl list-timersandjournalctl -u datelog.
Hints
crontab -e,crontab -l,*/2 * * * *;crontab -ror edit the line out.- The
atpackage and itsatdservice;atq,at -c,atrm. /etc/cron.deny,/etc/cron.allow;crontab -lasaliceshows the refusal.[Service]withType=oneshot,User=alice, and a shell for the>>:ExecStart=/bin/sh -c '...'.[Timer]and[Install] WantedBy=timers.target.systemd-analyze calendar '*:0/2'.