هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
الهدف
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
annaandbob(lab 6.1).
المهام
ضع علامة على المهمة عندما تنتهي منها. متصفحك فقط يتذكر ذلك.
- User
annamust runlogger "anna was here"every weekday (Monday to Friday) at 14:23. - As root, write the output of
df -h /to/var/tmp/disk.logevery 15 minutes, with a file in/etc/cron.d/. - User
bobmay not use cron. - In 5 minutes, write the text "at works" to
/tmp/at-test.txtwith at. Then plan a second at job and remove it. - Create a systemd timer
cleanup-tmp.timerthat runsfind /var/tmp -type f -mtime +7 -deleteevery 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.loggrows every 15 minutes.- bob gets "not allowed".
- After 5 minutes
/tmp/at-test.txtexists; 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
.servicewithType=oneshotplus a.timerwithOnCalendarandPersistent=true; enable the timer.
الحل
اعرض الحل
- anna's crontab.
crontab -e -u annacrontab -e -u anna23 14 * * 1-5 logger "anna was here" - The system cron file.
echo '*/15 * * * * root df -h / >> /var/tmp/disk.log' > /etc/cron.d/disk - Deny bob.
echo bob >> /etc/cron.deny - at jobs.
- 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
ملاحظاتي
لا توجد ملاحظات بعد.