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

معمل 12.1RHCSA 10, الفصل 12

Schedule jobs with cron, at and a timer

المستوى
متوسط
30 دقيقة
الأجهزة
server1
الحالة
لم يبدأ

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

الهدف

Plan repeating and one-time jobs with all three tools, and block one user from cron.

قبل أن تبدأ

  • Work on server1 as root. You need the users anna and bob (lab 6.1).

المهام

  1. User anna must run logger "anna was here" every weekday (Monday to Friday) at 14:23.
  2. As root, write the output of df -h / to /var/tmp/disk.log every 15 minutes, with a file in /etc/cron.d/.
  3. User bob may not use cron.
  4. In 5 minutes, write the text "at works" to /tmp/at-test.txt with at. Then plan a second at job and remove it.
  5. Create a systemd timer cleanup-tmp.timer that runs find /var/tmp -type f -mtime +7 -delete every day at 03:00, also when the machine was off at that time.

تحقّق من عملك

crontab -l -u anna
cat /etc/cron.d/disk
su - bob -c 'crontab -l'
atq
cat /tmp/at-test.txt
systemctl list-timers cleanup-tmp.timer
  • anna's crontab: 23 14 * * 1-5 logger "anna was here".
  • /var/tmp/disk.log grows every 15 minutes.
  • bob gets "not allowed".
  • After 5 minutes /tmp/at-test.txt exists; the second job is gone from atq.
  • The timer shows the next run at 03:00.

تلميحات

اعرض التلميحات
  • crontab -e -u anna. Day of week 1-5.
  • Files in /etc/cron.d need the user field.
  • /etc/cron.deny.
  • at now + 5 minutes; atq, atrm.
  • A .service with Type=oneshot plus a .timer with OnCalendar and Persistent=true; enable the timer.

الحل

اعرض الحل
  1. anna's crontab.
    crontab -e -u anna
    crontab -e -u anna
    23 14 * * 1-5 logger "anna was here"
  2. The system cron file.
    echo '*/15 * * * * root df -h / >> /var/tmp/disk.log' > /etc/cron.d/disk
  3. Deny bob.
    echo bob >> /etc/cron.deny
  4. at jobs.
    echo 'echo "at works" > /tmp/at-test.txt' | at now + 5 minutes
    echo 'reboot' | at 23:59
    atq
    atrm 2
  5. Service and timer.
    /etc/systemd/system/cleanup-tmp.service
    [Unit]
    Description=Delete old files in /var/tmp
     
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/find /var/tmp -type f -mtime +7 -delete
    /etc/systemd/system/cleanup-tmp.timer
    [Unit]
    Description=Daily cleanup of /var/tmp
     
    [Timer]
    OnCalendar=*-*-* 03:00:00
    Persistent=true
     
    [Install]
    WantedBy=timers.target
    systemctl daemon-reload
    systemctl enable --now cleanup-tmp.timer

ملاحظاتي

لا توجد ملاحظات بعد.

دروس هذا المعمل

الأوامر في هذا المعمل