Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Cloud

Linux Job Scheduling: cron, crontab, at and systemd Timers Explained

Some work must happen on its own: a backup every night, a report every Monday, a cleanup every hour. Linux gives you three tools for this. cron runs jobs on a repeating schedule. at runs a job once at a later time. systemd timers are the modern option with logs and catch-up built in. We learn each command and every time field, one by one.

In this chapter

  • Read and write the five cron time fields
  • Use crontab -e, -l, -r and -u
  • Use special strings and /etc/cron.d
  • Fix cron PATH, output and overlap problems
  • Run one-time jobs with at, atq and atrm
  • Write systemd timers with OnCalendar and Persistent

1. An everyday example: the milkman and the alarm

The milkman comes every day at 6 a.m. without being asked. That is a repeating schedule. Your phone alarm for the 4:30 p.m. dentist visit rings only once. And a good alarm app shows a 'missed alarm' if the phone was off, so you still know.

Milkman = cron. One-time alarm = at. Alarm app with missed-alarm = systemd timer with Persistent=true.

How cron runs a jobcrond wakes up every minuteIt reads user crontabs, /etc/crontab and /etc/cron.dIt compares each line's five fields with the current timeOn a match it starts the command with /bin/sh and a tiny PATHOutput is mailed or lost unless you redirect itThe run is logged in /var/log/cron or the journal
Cron normally uses the daemon’s time zone. Check it with timedatectl and look for a supported CRON_TZ override in the crontab.

2. The five time fields

Start with a proposed time and check one line by hand. 15 9 * * 1-5 means at minute 15 of hour 9, for any day of the month and any month, when the weekday is Monday through Friday. Write down Tuesday at 09:15 and Saturday at 09:15. Only Tuesday matches. A star means every allowed value for that field. Check the server time zone with date before comparing the chosen time with the clock on your laptop.

Every cron mistake starts with a wrong field. Learn them once and you can read any schedule.

minute (0-59), hour (0-23), day of month (1-31), month (1-12), day of week (0-7, 0 and 7 are Sunday). * = every. , = list (1,15). - = range (1-5). / = step (*/10). Then the command.

ScheduleMeaning
*/5 * * * *Every 5 minutes
0 2 * * *Every day at 02:00
30 9 * * 1-509:30 Monday to Friday
0 0 1 * *Midnight on the 1st of each month
0 */6 * * *Every 6 hours
15 10 * * 0Sunday 10:15
  1. A nightly backup at 2 a.m.
0 2 * * * /usr/local/bin/backup.sh

Output:

(a crontab line)

Minute 0, hour 2, every day.

  1. Office hours report.
30 9 * * 1-5 /usr/local/bin/report.sh

Output:

(a crontab line)

Weekdays only.

  1. Check a schedule before you trust it.
systemd-analyze calendar 'Mon..Fri 09:30'

Output:

  Original form: Mon..Fri 09:30
Normalized form: Mon..Fri *-*-* 09:30:00
    Next elapse: Mon 2026-10-26 09:30:00 IST

Shows the next run time.

3. crontab -e and -l: edit and list your jobs

Each user has a personal crontab. Editing it through crontab checks syntax and tells crond.

crontab -e opens your crontab in $EDITOR. Save to install. crontab -l prints it. Never edit /var/spool/cron files by hand. Lines starting with # are comments.

  1. Open the editor.
EDITOR=nano crontab -e

Output:

crontab: installing new crontab

Printed after you save.

  1. List your jobs.
crontab -l

Output:

# nightly backup
0 2 * * * /usr/local/bin/backup.sh

What cron will run for you.

  1. No crontab yet.
crontab -l

Output:

no crontab for ec2-user

Normal for a new user.

4. crontab FILE, -r and -u

Automation tools install crontabs from files. Admins sometimes manage another user's jobs.

crontab FILE replaces your whole crontab with the file. crontab -r deletes all your jobs with no question (-i asks first). sudo crontab -u USER -l or -e works on another user. Back up first: crontab -l > ~/cron.bak.

  1. Back up your jobs.
crontab -l > ~/cron.bak && wc -l ~/cron.bak

Output:

2 /home/ec2-user/cron.bak

Do this before any change.

  1. Install from a file.
crontab ~/cron.bak

Output:

(no output)

Replaces everything.

  1. See the app user's jobs.
sudo crontab -u shop -l

Output:

*/10 * * * * /opt/shop/bin/sync

Read-only look.

  1. Delete with a question.
crontab -ri

Output:

crontab: really delete ec2-user's crontab? (y/n)

-r alone does not ask. Careful.

5. Special strings: @reboot, @daily and more

Some schedules are easier to read as words. @reboot is the only way in cron to run once at boot.

@reboot (at crond start), @hourly (0 * * * *), @daily or @midnight (0 0 * * *), @weekly (0 0 * * 0), @monthly (0 0 1 * *), @yearly (0 0 1 1 *).

  1. Warm a cache after boot.
@reboot sleep 30 && /opt/shop/bin/warm-cache

Output:

(a crontab line)

sleep gives the network time.

  1. Weekly cleanup.
@weekly find /tmp/shop -mtime +7 -delete

Output:

(a crontab line)

Sunday midnight.

6. /etc/crontab, /etc/cron.d and cron.daily

System and package jobs live in files, not in a user's crontab, so they can be shipped and reviewed in Git.

Files in /etc/cron.d and /etc/crontab have a sixth field: the user. Scripts in /etc/cron.hourly, daily, weekly, monthly run by run-parts (or anacron); they must be executable and have no dot in the name on Debian.

  1. A system job with a user field.
echo '*/15 * * * * shop /opt/shop/bin/sync >> /var/log/shop/sync.log 2>&1' | sudo tee /etc/cron.d/shop-sync

Output:

*/15 * * * * shop /opt/shop/bin/sync >> /var/log/shop/sync.log 2>&1

Runs as user shop.

  1. A daily script.
sudo install -m 755 cleanup.sh /etc/cron.daily/cleanup

Output:

(no output)

No .sh extension, mode 755.

  1. Which daily scripts will run?
run-parts --test /etc/cron.daily

Output:

/etc/cron.daily/cleanup
/etc/cron.daily/logrotate

Lists what would run.

7. The cron environment: PATH, SHELL and MAILTO

When you run a report manually, your shell may be in the report’s folder and may already know where your private tools live. Cron launches the job in a separate environment. Write the script’s full path. Make its input and output paths explicit, or have the script change into its working directory and stop with a clear error if that fails. In a test job, write pwd, date and the value of PATH into a lab log. Compare the result with your terminal until you can account for every difference.

'It works in my terminal but not in cron' is the most common cron problem. cron gives you a tiny environment.

cron uses /bin/sh, PATH=/usr/bin:/bin, HOME of the user, no .bashrc. Fix: use full paths, or set PATH= and SHELL= at the top of the crontab. MAILTO=you@x sends output by mail; MAILTO="" turns mail off. % is special in cron: escape as \%.

  1. See cron's environment.
* * * * * env > /tmp/cron-env.txt

Output:

(after one minute) PATH=/usr/bin:/bin
SHELL=/bin/sh
HOME=/home/ec2-user

Very small PATH.

  1. Set it at the top.
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=""

Output:

(crontab header lines)

Now jobs find aws, node and others.

  1. Escape % in a date.
0 1 * * * tar czf /backup/site-$(date +\%F).tgz /var/www

Output:

(a crontab line)

Without \ the line is cut at %.

8. Logging cron output and checking runs

A silent failing job is worse than no job. You need proof it ran and what it printed.

Redirect: >> /var/log/job.log 2>&1 keeps output and errors. cron runs are logged in /var/log/cron (RHEL) or the journal (journalctl -u cron or -u crond). Or pipe to logger -t job.

  1. Keep output.
0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1

Output:

(a crontab line)

2>&1 also catches errors.

  1. Did it run?
journalctl -u crond --since today --no-pager | grep backup

Output:

Oct 25 02:00:01 web1 CROND[3301]: (root) CMD (/usr/local/bin/backup.sh >> /var/log/backup.log 2>&1)

It started at 02:00:01.

  1. Send output to the journal.
*/5 * * * * /opt/shop/bin/sync 2>&1 | logger -t shop-sync

Output:

(a crontab line)

Read with journalctl -t shop-sync.

9. flock: stop jobs from overlapping

If a 5-minute job sometimes takes 7 minutes, two copies run together and can corrupt data.

flock -n /tmp/NAME.lock COMMAND runs only if it gets the lock; -n means give up at once if busy. The lock is freed when the command ends.

  1. Safe 5-minute sync.
*/5 * * * * flock -n /tmp/sync.lock /opt/shop/bin/sync

Output:

(a crontab line)

A second copy just exits.

  1. Test by hand.
flock -n /tmp/demo.lock sleep 60 & sleep 1; flock -n /tmp/demo.lock echo second; echo exit=$?

Output:

exit=1

Second run was refused.

10. at: run a job once later

Some tasks happen once: restart at 11 p.m. tonight, remove a temporary firewall rule in 2 hours.

Install the at package and start atd. at TIME reads commands from stdin; finish with Ctrl+D. TIME like 23:00, now + 2 hours, 'tomorrow 09:00', noon. -f FILE reads from a file. batch runs when load is low.

  1. Start atd.
sudo systemctl enable --now atd

Output:

(no output)

Without atd nothing runs.

  1. Restart tonight at 11.
echo 'systemctl restart shop-api' | sudo at 23:00

Output:

job 4 at Sun Oct 25 23:00:00 2026

Job number 4.

  1. Undo a rule in 2 hours.
echo 'firewall-cmd --remove-port=8080/tcp' | sudo at now + 2 hours

Output:

job 5 at Sun Oct 25 14:45:00 2026

A safety net.

11. atq, at -c and atrm

You must be able to see and cancel pending one-time jobs.

atq lists pending jobs (sudo atq for all). at -c N prints what job N will run. atrm N deletes it.

  1. List.
sudo atq

Output:

4	Sun Oct 25 23:00:00 2026 a root
5	Sun Oct 25 14:45:00 2026 a root

Number, time, queue, user.

  1. Look inside.
sudo at -c 4 | tail -n 2

Output:

systemctl restart shop-api

The last lines are your commands.

  1. Cancel.
sudo atrm 4 && sudo atq

Output:

5	Sun Oct 25 14:45:00 2026 a root

Job 4 gone.

12. systemd timers: OnCalendar and Persistent

Keep two files apart in your mind. The timer says when to start, and the matching service says which command to run. Test the service once directly to prove the command works. Then read the timer’s next run and check the journal afterward for the service outcome. For a calendar timer with Persistent=true, systemd can start the service once when the timer returns after one or more missed times. If the job must process a separate record for every missing day, make the service track and catch up on those dates itself.

Timers give you journal logs, resource limits, no overlap and catch-up after downtime, for free.

You need two files: NAME.service (what to run, Type=oneshot) and NAME.timer (when). OnCalendar=*-*-* 02:00:00 or daily, Mon..Fri 09:30. OnBootSec=5min and OnUnitActiveSec=1h for intervals. Persistent=true runs a missed job at boot. RandomizedDelaySec spreads load. Enable the timer, not the service.

  1. The service.
sudo tee /etc/systemd/system/backup.service <<'X'
[Unit]
Description=Nightly backup
[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
X

Output:

(file text)

No [Install] needed.

  1. The timer.
sudo tee /etc/systemd/system/backup.timer <<'X'
[Unit]
Description=Run backup daily at 2
[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true
RandomizedDelaySec=10min
[Install]
WantedBy=timers.target
X

Output:

(file text)

Same base name as the service.

  1. Enable the timer.
sudo systemctl daemon-reload && sudo systemctl enable --now backup.timer

Output:

Created symlink /etc/systemd/system/timers.target.wants/backup.timer → /etc/systemd/system/backup.timer.

Now it is scheduled.

  1. Run it now once to test.
sudo systemctl start backup.service && journalctl -u backup -n 3 --no-pager

Output:

Oct 25 12:50:01 web1 systemd[1]: Finished Nightly backup.

Logs come free.

13. systemctl list-timers

You need one view of every timer: when it last ran and when it runs next.

systemctl list-timers shows active timers with NEXT, LEFT, LAST, PASSED, UNIT, ACTIVATES. --all includes inactive ones.

  1. All timers.
systemctl list-timers --no-pager | head -3

Output:

NEXT                        LEFT     LAST                        PASSED  UNIT              ACTIVATES
Mon 2026-10-26 02:04:11 IST 13h left Sun 2026-10-25 12:50:01 IST 3s ago backup.timer      backup.service
Mon 2026-10-26 00:00:00 IST 11h left Sun 2026-10-25 00:00:00 IST 12h ago logrotate.timer   logrotate.service

The random delay shows as 02:04.

  1. Test an expression.
systemd-analyze calendar --iterations=3 'Mon *-*-* 08:00'

Output:

Next elapse: Mon 2026-10-26 08:00:00 IST
       Iter. #2: Mon 2026-11-02 08:00:00 IST
       Iter. #3: Mon 2026-11-09 08:00:00 IST

Three next runs.

14. Real examples from many industries

The same Linux skill shows up in every kind of company. Seeing it in many places helps you remember it.

Each row is a made-up team. It shows who uses this and how.

Team and cityHow they use itCommand
Neha, CA firm, PuneEmails a GST report every 1st0 8 1 * * /opt/ca/gst-report.sh
Oliver, news site, SydneyClears page cache every 10 minutes*/10 * * * * flock -n /tmp/c.lock /opt/news/purge
Zainab, airline, DohaUses timers with Persistent for crew rosterssystemctl list-timers
Lucas, bank, FrankfurtSchedules a one-time change window jobat 23:30 -f change.sh
Priya, school ERP, KolhapurBacks up the DB at 2 a.m. with logs0 2 * * * /opt/erp/backup.sh >> /var/log/erp-backup.log 2>&1
Ken, logistics, TorontoRuns a sync after each boot@reboot /opt/fleet/sync

15. Common errors and how to fix them

Everyone hits these errors. Knowing the cause saves hours.

Read the exact message first. Then match it to a row below.

Error you seeWhy it happensHow to fix
/bin/sh: aws: command not found (in cron mail/log)cron PATH is tinyUse full paths or set PATH in crontab.
which aws
no crontab for ec2-userYou have no jobs yetCreate one with crontab -e.
crontab -e
"/tmp/crontab.X":1: bad minute errors in crontab file, can't install.Wrong field count or valueFive fields then the command.
crontab -e
Job runs at the wrong hourServer time zone is UTCCheck timedatectl; adjust the hour or the zone.
timedatectl
Command cut off at % sign% means newline in cronEscape it as \%.
date +\%F
Job in /etc/cron.daily never runsNot executable or has a dot in the namechmod 755 and remove .sh.
run-parts --test /etc/cron.daily
Can't open display / permission denied in cronDifferent user, no GUI, wrong permissionsRun as the right user; avoid GUI tools.
sudo crontab -u shop -l
Can't open /var/run/atd.pid to signal atd. No atd running?atd service is not runningStart atd.
sudo systemctl enable --now atd
Two copies of the job run togetherJob slower than its intervalWrap with flock -n.
flock -n /tmp/job.lock /opt/job
Timer is enabled but never firesEnabled the .service, not the .timer, or no daemon-reloadEnable the timer and check list-timers.
sudo systemctl enable --now backup.timer

16. Troubleshooting step by step

If a scheduled job did not do its work, prove each link: schedule, start, environment, output.

Go top to bottom. Stop at the first step that shows the problem.

  1. Is the job installed?
crontab -l; ls /etc/cron.d
  1. Is cron running?
systemctl is-active crond
  1. Did cron start it?
journalctl -u crond --since today --no-pager | tail
  1. Run it with cron's environment.
env -i SHELL=/bin/sh PATH=/usr/bin:/bin HOME=$HOME /bin/sh -c '/usr/local/bin/backup.sh'
  1. Read its own output log.
tail -n 30 /var/log/backup.log
  1. For timers, check next run and logs.
systemctl list-timers --all; journalctl -u backup -n 20

17. Lab 1: A safe cron job with logs and a lock

Write a job that runs every minute, logs output, cannot overlap, then remove it.

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

  1. Back up crontab.
crontab -l > ~/cron.bak 2>/dev/null; echo saved

Output:

saved
  1. Add the job.
(crontab -l 2>/dev/null; echo '* * * * * flock -n /tmp/tick.lock /bin/date >> /tmp/tick.log 2>&1') | crontab -

Output:

(no output)
  1. Confirm.
crontab -l | tail -n1

Output:

* * * * * flock -n /tmp/tick.lock /bin/date >> /tmp/tick.log 2>&1
  1. Wait 2 minutes and read.
sleep 125; cat /tmp/tick.log

Output:

Sun Oct 25 13:01:01 IST 2026
Sun Oct 25 13:02:01 IST 2026
  1. Restore.
crontab ~/cron.bak 2>/dev/null || crontab -r; crontab -l

Output:

(your old jobs)

18. Lab 2: Replace a cron job with a systemd timer, plus at

Build a timer that runs every 2 minutes, view it, then schedule a one-time at job and cancel it.

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

  1. Service.
printf '[Service]\nType=oneshot\nExecStart=/usr/bin/logger -t tick hello\n' | sudo tee /etc/systemd/system/tick.service

Output:

[Service]
  1. Timer.
printf '[Timer]\nOnBootSec=1min\nOnUnitActiveSec=2min\n[Install]\nWantedBy=timers.target\n' | sudo tee /etc/systemd/system/tick.timer && sudo systemctl daemon-reload && sudo systemctl enable --now tick.timer

Output:

Created symlink ... tick.timer
  1. See it.
systemctl list-timers tick.timer --no-pager

Output:

NEXT ... tick.timer tick.service
  1. at job then cancel.
echo 'logger -t atlab hi' | at now + 30 minutes; atq; atrm $(atq | awk '{print $1}' | tail -n1); atq

Output:

job 7 at Sun Oct 25 13:35:00 2026
  1. Clean up.
sudo systemctl disable --now tick.timer && sudo rm /etc/systemd/system/tick.* && sudo systemctl daemon-reload

Output:

Removed ... tick.timer

Ravindra Bagale's Tip

Before you trust a schedule, test it: systemd-analyze calendar for timers, and for cron write the line, then check the journal after the first run. And always redirect output; a cron job with no log is a job you cannot debug.

19. Frequently asked questions

Q. cron or systemd timer?

Timers for new server jobs (logs, catch-up, limits). cron is simple and everywhere.

Q. Can cron run every 30 seconds?

Not directly; minimum is 1 minute. Use a timer with OnUnitActiveSec=30s.

Q. What if the server was off at 2 a.m.?

cron skips it; anacron or Persistent=true timers catch up.

Q. Which time zone does cron use?

The system zone (timedatectl). CRON_TZ= works on some systems.

Q. Who may use crontab?

Controlled by /etc/cron.allow and /etc/cron.deny.

Q. Is crontab -r dangerous?

Yes, deletes all your jobs at once. Back up first.

Q. Day of month and day of week both set?

Cron runs when either matches.

Q. How to run a timer job right now?

systemctl start NAME.service.

20. Interview questions and answers

Beginner level

Q. What are the five cron fields?

minute hour day-of-month month day-of-week.

Q. How do you list your cron jobs?

crontab -l.

Q. Every 5 minutes in cron?

*/5 * * * *.

Q. How do you run a job once at 10 p.m.?

echo cmd | at 22:00.

Mid level level

Q. Why does a script fail only in cron?

Minimal PATH and environment; use full paths.

Q. How do you stop overlapping runs?

flock -n lockfile cmd, or a timer.

Q. What is different in /etc/cron.d files?

They have a user field.

Q. Which two files make a systemd timer?

NAME.service and NAME.timer.

Senior level

Q. Missed jobs after downtime: how to handle?

Persistent=true timers or anacron; make jobs idempotent.

Q. Cron at scale across 100 servers?

Avoid thundering herd with RandomizedDelaySec or jitter, central logging, single-runner locks.

Q. How would you monitor that a nightly job ran?

Job pings a heartbeat or writes a metric; alert on missing run.

Q. DST and cron?

Jobs in skipped or repeated hours may run 0 or 2 times; use UTC on servers.

Try at home

  1. Write a cron line that runs df -h every hour and appends to ~/disk.log. Check the file after two hours.
  2. Convert the same job into a systemd timer with OnCalendar=hourly and Persistent=true.

Practise this chapter

Interview questions and answers

A script runs in your terminal but fails as a scheduled job. Where do you start?

Compare the account, working directory, environment and paths in the scheduled run with the manual run. Log an explicit time and exit status. Use the same test input with full paths in both runs to isolate whether the command or the scheduler is responsible.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. Which weekday time matches 15 9 * * 1-5 in the scheduler’s local zone?

Answer and explanation

C. Tuesday 09:15

Cron reads minute first, then hour. The final field limits this expression to the weekdays Monday through Friday.

2. Which systemd file describes the command started by a timer?

Answer and explanation

A. The service unit

The timer chooses when and which unit to activate. The associated service contains the commands and execution settings.

3. A persistent daily timer missed two days while its host was off. What should the job implement if it owes two date-specific reports?

Answer and explanation

B. Track completed dates and explicitly catch up on missing ones

The timer can catch up by triggering after missed opportunities. The service needs its own logic to process each missing date.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

About this scenario

London Legal LLP is a law business in London. Oliver Hughes looks after its IT and cloud work. They count money in GBP and run their AWS resources in the eu-west-2 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 16

Easy List my cron jobs

Automation saves time.

Show your crontab.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Edit crontab

Automation saves time.

Open your crontab for editing.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Pending at jobs

Automation saves time.

List pending at jobs.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy List timers

Automation saves time.

List all systemd timers including inactive.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Another user

Automation saves time.

As root, list the crontab of user deploy.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Is cron running?

Automation saves time.

Check the status of the crond service.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Did cron run?

Automation saves time.

Search the journal of crond for today.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium One-time job

Automation saves time.

Schedule /opt/report.sh to run at 18:00 with at.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Cancel at job

Automation saves time.

Cancel at job number 7.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Start atd

Automation saves time.

Enable and start atd.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Start a timer

Automation saves time.

Enable and start backup.timer.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Remove all jobs

Automation saves time.

Remove your whole crontab after asking.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Check a schedule

Automation saves time.

Check when "Mon..Fri 09:00" would next fire.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Run the job now

Automation saves time.

Run backup.service immediately to test it.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Timer job logs

Automation saves time.

Show the last 20 lines of backup.service logs.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Transient timer

Automation saves time.

Run /opt/cleanup.sh once in 30 minutes with systemd-run.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

In short

  1. Five fields: minute hour dom month dow.
  2. crontab -e/-l/-r/-u manage user jobs.
  3. /etc/cron.d adds a user field; @reboot runs at boot.
  4. Full paths, redirects and flock make cron safe.
  5. at, atq, atrm for one-time jobs.
  6. Timers = .service + .timer, OnCalendar, Persistent, list-timers.

Revision, comparison and interview cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

cron 5 fields. Run jobs on a schedule. min hour day month weekday. Use full paths, log output. Edit your jobs.
Revision card: cron 5 fields · Download PNG · Open card page
systemd timers. Cron with logs and catch-up. .timer starts a .service. Persistent=true runs missed jobs. See next runs.
Revision card: systemd timers · Download PNG · Open card page
cron vs systemd timer. One line in crontab. / Two unit files.
Comparison: cron vs systemd timer · Download PNG · Open card page
cron vs at. Again and again. / Once.
Comparison: cron vs at · Download PNG · Open card page
Works in shell, not cron?. cron has a tiny PATH. Use full paths, log output. Check cron logs.
Interview card: Works in shell, not cron? · Download PNG · Open card page
cron vs timer?. cron: simple, everywhere. timer: logs, deps, catch-up. List timers.
Interview card: cron vs timer? · Download PNG · Open card page
When to use at?. One-time future job. atq lists, atrm cancels. Schedule at 18:00.
Interview card: When to use at? · Download PNG · Open card page
Stop jobs overlapping?. Long run meets next start. Use flock in cron. Lock a job.
Interview card: Stop jobs overlapping? · Download PNG · Open card page

More cards: Ravi Sir's Cards.