متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 225System · Scheduling

How to run a command once at a set time

"Restart the app tonight at 02:00", "remove this temporary firewall rule in 2 hours", "if my change locks me out, undo it in 10 minutes" — jobs that run once. Cron is for repeating jobs; for one-time jobs use at, or systemd-run with a timer. This how-to schedules, lists and cancels one-time jobs with both, including the classic safety net for risky remote changes.

  • 5 الدروس
  • 6 الأوامر

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

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

225.1

The quick answer

systemctl enable --now atd
echo "systemctl restart myapp" | at 02:00
atq
atrm 3

225.2

Step by step

  1. Install and start atd (package at) — line 1.
  2. Schedule (line 2) — the command runs as you, from the current folder, with your environment. Time formats: 02:00, now + 2 hours, 16:30 tomorrow, noon 2026-12-24. A script file: at now + 30 minutes -f /root/cleanup.sh.
  3. List and check — atq shows job number, time and user; at -c 3 prints the full script of job 3 (check what will really run).
  4. Cancel (line 4) — atrm 3.
  5. Safety net for risky remote changes — before you change the firewall or SSH on a remote server, schedule the undo:
echo "cp /root/nftables.conf.bak /etc/nftables.conf && systemctl restart nftables" | at now + 10 minutes

Make the change; if you can still log in, cancel the job with atrm. If you locked yourself out, the job restores access in 10 minutes.

  1. Output — at mails the output to the user if a local mail system exists; otherwise redirect it yourself: … > /var/log/at-restart.log 2>&1.
  2. The systemd way — a transient timer, logged in the journal:
systemd-run --on-calendar='2026-11-21 02:00' --unit=restart-myapp systemctl restart myapp
systemctl list-timers restart-myapp.timer
journalctl -u restart-myapp.service

Relative: --on-active=2h. Cancel: systemctl stop restart-myapp.timer.

  1. Who may use at — /etc/at.allow (only these users) or /etc/at.deny.

225.3

Check that it worked

atq lists the job with the right time; after that time the job is gone from atq and its effect is visible (the app's ActiveEnterTimestamp in systemctl show myapp -p ActiveEnterTimestamp, or your log file); for systemd-run, journalctl -u restart-myapp.service shows the run.

225.4

Common problems

ProblemCauseFix
Can't open /var/run/atd.pid to signal atdatd not running.systemctl enable --now atd.
Job ran but did nothingDifferent PATH or folder; error output lost.Full paths; redirect output to a log file.
You do not have permission to use atNot in at.allow / listed in at.deny.Edit the allow/deny files.
Job ran at the wrong hourServer time zone differs from yours.Check timedatectl; give the time in the server's zone.
Transient timer gone after rebootsystemd-run timers are not persistent.Use at (jobs survive reboot) or a real timer unit.
Safety-net job not cancelledForgot atrm.Always run atq after a successful change.

225.5

Go further

1What is the difference between at and cron?

at runs a job once at a set time; cron repeats a job on a schedule.

2How can at protect you during a risky remote firewall change?

Schedule the undo first; if you lock yourself out, it restores access, and if not, you cancel it with atrm.

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