الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

الفصل 3الاسم في الدورة: Scheduling User Tasks

Run your own jobs later or on a schedule

A normal user can schedule work without root: run a command once at a later time with at, or again and again with a personal crontab or a systemd user timer. This chapter shows all three, and how to check that the jobs really run.

  • 6 الدروس
  • 12 الأوامر
  • 1 المعامل

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

المهارات في هذا الفصل

  • تشغيل المهام لاحقًا أو بجدول زمني كمستخدم عادي

3.1

Run a command once later with at

at TIME reads commands and runs them one time at that time. The atd service must run.

systemctl enable --now atd
at 22:30
at> tar czf ~/backup-$(date +%F).tar.gz ~/Documents
at> <EOT>
job 7 at Mon Oct 27 22:30:00 2026
echo "systemctl --user restart myapp" | at now + 15 minutes
at -f ~/bin/report.sh tomorrow 06:00
atq
7       Mon Oct 27 22:30:00 2026 a student
8       Mon Oct 27 12:05:00 2026 a student
at -c 7 | tail -n 3
atrm 8
batch < ~/bin/heavy-job.sh

Press Ctrl+D to end the input of at (it shows <EOT>).

Time formatMeans
22:30, 10:15 PMThe next time it is that hour
now + 30 minutes, now + 2 hours, now + 3 daysFrom now
tomorrow 06:00, noon, midnight, teatime (16:00)Named times
2026-12-31 23:00An exact date and time

batch runs the job when the load is low (below 0.8).

تذكّر

atq lists, at -c N shows the full job, atrm N removes it.

3.2

Write a personal crontab

crontab -e opens your cron table. Each line = 5 time fields + a command. crond runs it with your rights.

crontab -e
crontab -l
*/15 * * * * /home/student/bin/checkdisk.sh >> /home/student/disk.log 2>&1
0 7 * * 1-5 /home/student/bin/report.sh
@reboot /home/student/bin/start-tunnel.sh
crontab -r
crontab -u anna -l
┌──────── minute       (0-59)
│ ┌────── hour         (0-23)
│ │ ┌──── day of month (1-31)
│ │ │ ┌── month        (1-12 or jan-dec)
│ │ │ │ ┌ day of week  (0-7 or sun-sat; 0 and 7 = Sunday)
│ │ │ │ │
* * * * *  command
ExampleRuns
30 2 * * *Every day at 02:30
*/10 * * * *Every 10 minutes
0 9-17 * * 1-5Every full hour from 9 to 17, Monday to Friday
0 0 1 * *At midnight on the first day of every month
15 3 * * 0Sundays at 03:15
@daily / @weekly / @rebootOnce a day / once a week / at boot

انتبه

When day of month and day of week are both set, cron runs the job when either matches. 0 8 1 * 1 runs on the 1st and on every Monday.

الأوامر في هذا الدرس

3.3

Make cron jobs work like in the shell

Cron jobs run with a very small environment: few variables, a short PATH, no terminal. Write the job so it does not depend on your login shell.

  • Use full paths for commands and files: /usr/bin/rsync, not rsync.
  • Send the output to a log: >> /home/student/job.log 2>&1. Otherwise cron tries to mail it.
  • % is special in a crontab: write date +\%F.
  • Set variables at the top of the crontab when you need them.
crontab -e
PATH=/usr/local/bin:/usr/bin:/bin
MAILTO=""
0 1 * * * /home/student/bin/backup.sh >> /home/student/backup.log 2>&1
5 1 * * * tar czf /home/student/etc-$(date +\%F).tgz /home/student/etc

في العمل

Test the command first with env -i /bin/bash -c 'COMMAND' — that is close to the clean environment cron uses.

3.4

Check that cron jobs ran

crond logs every start in the journal (and in /var/log/cron).

crontab -l
journalctl -u crond --since today
grep student /var/log/cron | tail -n 5
Oct 27 12:15:01 server1 CROND[6120]: (student) CMD (/home/student/bin/checkdisk.sh >> /home/student/disk.log 2>&1)
tail -n 3 ~/disk.log

Control who may use cron and at:

FileEffect
/etc/cron.allowIf it exists, only these users may use crontab
/etc/cron.denyThese users may not (used when cron.allow does not exist)
/etc/at.allow, /etc/at.denyThe same for at

3.5

Use a systemd user timer

A user timer is a timer unit in ~/.config/systemd/user/. It starts a user service, logs in the journal, and can catch up on missed runs.

~/.config/systemd/user/report.service
[Unit]
Description=Make my daily report
 
[Service]
Type=oneshot
ExecStart=/home/student/bin/report.sh
~/.config/systemd/user/report.timer
[Unit]
Description=Run my report every work day at 07:00
 
[Timer]
OnCalendar=Mon..Fri 07:00
Persistent=true
 
[Install]
WantedBy=timers.target
systemctl --user daemon-reload
systemctl --user enable --now report.timer
systemctl --user list-timers
journalctl --user -u report.service
loginctl enable-linger student
loginctl show-user student -p Linger
Linger=yes

تذكّر

User services run only while the user is logged in — unless linger is on. loginctl enable-linger USER lets the user's timers and services run all the time, also after a reboot.

ملاحظة

Persistent=true runs a missed job at the next start (for example when the laptop was off at 07:00).

3.6

Choose the right tool

All three tools run jobs, but each one fits a different case.

NeedUse
Run something once, later today or tomorrowat
A simple repeating job, classic syntax everybody knowscrontab -e
Logs in the journal, missed runs caught up, dependencies, resource limitssystemd timer
systemd-run --user --on-calendar='*-*-* 18:00' /home/student/bin/sync.sh
systemd-run --user --on-active=30m /usr/bin/notify-send "Break!"

systemd-run makes a temporary timer without writing unit files — like at, but in systemd.

تدرّب

كل الأوامر في هذا الفصل