CT320: Network and System Administration

Fall 2018

Periodic

See this page as a slide show

CT320 Periodic

CHAPTER 9: PERIODIC PROCESSES

Original slides from Dr. James Walden at Northern Kentucky University.

Topics

  1. Overview
  2. Cron Daemon
  3. Crontab Format
  4. Crontab Command
  5. Common Uses

Overview

Daemons

$ ps -e | grep 'd$' | sort -k4 -u
  343 ?        00:00:00 /usr/sbin/httpd
 1952 ?        00:00:00 atd
13144 ?        00:00:05 cleanupd
 1895 ?        00:00:49 colord
 1949 ?        00:00:07 crond
15078 ?        00:00:00 cupsd
27859 ?        00:00:00 gsd-clipboard
27872 ?        00:00:00 gsd-keyboard
27894 ?        00:00:00 gsd-smartcard
27897 ?        00:00:00 gsd-sound
25476 ?        00:00:39 hpsmhd
  157 ?        00:00:00 kaluad
  294 ?        00:00:00 kauditd
  119 ?        00:00:00 kblockd
  130 ?        00:00:15 khugepaged
  113 ?        00:00:05 khungtaskd
  115 ?        00:00:00 kintegrityd
  156 ?        00:00:00 kmpath_rdacd
  166 ?        00:00:00 kpsmoused
  129 ?        00:00:00 ksmd
    2 ?        00:00:11 kthreadd
  139 ?        00:00:00 kthrotld
 1581 ?        00:00:17 lmgrd
 1590 ?        00:17:42 lockd
  120 ?        00:00:00 md
 1598 ?        00:00:01 nfsd
 2034 ?        00:00:00 nfsiod
 1485 ?        00:00:58 nmbd
 1209 ?        00:01:29 ntpd
 1879 ?        02:08:01 polkitd
   10 ?        05:54:14 rcu_sched
 1517 ?        00:00:00 rhsmcertd
 1198 ?        00:00:00 rpc.idmapd
 1542 ?        00:00:00 rpc.mountd
 1515 ?        00:02:17 rpc.statd
 1202 ?        00:06:40 rpcbind
  655 ?        00:00:00 rpciod
 1513 ?        00:03:29 rsyslogd
 1220 ?        00:00:00 smartd
 3336 ?        00:00:00 smbd
13143 ?        00:00:03 smbd-notifyd
 1509 ?        00:00:30 sshd
    1 ?        00:09:15 systemd
 1871 ?        00:01:26 systemd-logind
  684 ?        00:00:01 systemd-udevd
 9138 ?        00:00:04 udisksd
 3226 ?        00:00:10 upowerd
  656 ?        00:00:00 xprtiod
 1554 ?        00:00:12 ypbind

Topics

  1. Overview
  2. Cron Daemon
  3. Crontab Format
  4. Crontab Command
  5. Common Uses

cron Daemon

Permissions

$ cat /usr/lib/systemd/system/crond.service
[Unit]
Description=Command Scheduler
After=auditd.service systemd-user-sessions.service time-sync.target

[Service]
EnvironmentFile=/etc/sysconfig/crond
ExecStart=/usr/sbin/crond -n $CRONDARGS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process

[Install]
WantedBy=multi-user.target

$ ls -l /usr/sbin/crond
-rwxr-xr-x 1 root root 70208 Oct 16  2017 /usr/sbin/crond

Is crond SUID? How does it execute your crontab as you?
It’s executed as root by systemd.

Topics

  1. Overview
  2. Cron Daemon
  3. Crontab Format
  4. Crontab Command
  5. Common Uses

crontab Format

Comment lines starting with ‘#’ are ignored by the daemon. Otherwise:

LabelRangeDescription
Minute0–59Minute of Hour
Hour0–23Hour of Day
Day1–31Day of Month
Month1–12Month of Year (or “Jan”, “Feb”, …)
Weekday0–6Day of Week (0=Sunday) (or “Sun”, “Mon”, …)

crontab Schedules

    # Minute, Hour, Day of Month, Month, Weekday

      *     *  *  *   *  echo Every minute
     00     *  *  *   *  echo Every hour
     00     1  *  *   *  echo Every day at 1:00ᴀᴍ
     30   */3  *  *   *  echo Every three hours, on the half-hour
     00    23  *  *   0  echo 11:00ᴘᴍ Sundays
    */5  9-17  *  * 1-5  echo Every five minutes, during working hours
     45 10,22  *  * 0,6  echo 10:45ᴀᴍ and 10:45ᴘᴍ on weekends
     00     8 25 12   *  echo Christmas morning

crontab shortcuts

    @reboot    :  Run once after reboot.
    @yearly    :  Run once a year, i.e.,  “0 0 1 1 *”.
    @annually  :  Run once a year, i.e.,  “0 0 1 1 *”.
    @monthly   :  Run once a month, i.e., “0 0 1 * *”.
    @weekly    :  Run once a week, i.e.,  “0 0 * * 0”.
    @daily     :  Run once a day, i.e.,   “0 0 * * *”.
    @hourly    :  Run once an hour, i.e., “0 * * * *”.

What cron cannot do

crontab Example

    PATH=/usr/local/bin:/home/bonehead/bin:/bin:/usr/bin
    MAILTO=Bonehead@ColoState.Edu
    0 2 1-10 * * du -h -c -d=1 /

Topics

  1. Overview
  2. Cron Daemon
  3. Crontab Format
  4. Crontab Command
  5. Common Uses

crontab Command

Topics

  1. Overview
  2. Cron Daemon
  3. Crontab Format
  4. Crontab Command
  5. Common Uses

Common Uses

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2018-09-10T18:26

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building