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
   2368 ?        00:00:00 atd
   1049 ?        00:00:23 chronyd
3706189 ?        00:00:20 crond
   6510 ?        00:00:00 gvfsd
    208 ?        00:00:00 kaluad
     98 ?        00:00:00 kauditd
    107 ?        00:00:00 kblockd
    104 ?        00:01:12 khugepaged
     99 ?        00:00:05 khungtaskd
    106 ?        00:00:00 kintegrityd
    207 ?        00:00:00 kmpath_rdacd
    103 ?        00:00:00 ksmd
   1101 ?        00:01:18 ksmtuned
      2 ?        00:00:05 kthreadd
    197 ?        00:00:00 kthrotld
1625688 ?        00:00:00 kworker/0:6H-kblockd
 884148 ?        00:00:00 kworker/10:2H-kblockd
4077392 ?        00:00:00 kworker/11:1H-kblockd
1607453 ?        00:00:00 kworker/1:3H-kblockd
1601564 ?        00:00:00 kworker/2:0H-kblockd
1233123 ?        00:00:00 kworker/3:1H-kblockd
 762247 ?        00:00:00 kworker/4:1H-kblockd
 292231 ?        00:00:00 kworker/5:8H-kblockd
 496782 ?        00:00:00 kworker/6:0H-kblockd
4105640 ?        00:00:00 kworker/7:1H-kblockd
1833380 ?        00:00:03 kworker/8:1H-kblockd
1582232 ?        00:00:01 kworker/9:0H-kblockd
1311036 ?        00:00:03 kworker/u24:0-xprtiod
1589051 ?        00:00:00 kworker/u24:1-xprtiod
1638380 ?        00:00:00 kworker/u24:2-nfsiod
1523802 ?        00:00:01 kworker/u24:3-xprtiod
   1874 ?        00:00:00 lockd
   1054 ?        00:00:05 lsmd
    111 ?        00:00:00 md
   1856 ?        00:00:00 nfsiod
   1686 ?        00:10:29 pmcd
   1043 ?        00:13:50 polkitd
     14 ?        00:15:59 rcu_sched
   1396 ?        00:00:00 rhsmcertd
   1036 ?        00:00:05 rpcbind
   1065 ?        00:00:00 rpciod
   1421 ?        00:00:01 rpc.statd
   1403 ?        00:10:31 rsyslogd
   1398 ?        00:00:00 sshd
      1 ?        01:11:03 systemd
   2318 ?        00:16:15 systemd-logind
    695 ?        00:04:19 systemd-udevd
   1390 ?        04:29:24 tuned
   1777 ?        00:02:04 /usr/sbin/httpd
    113 ?        00:00:00 watchdogd
   1066 ?        00:00:00 xprtiod
   1140 ?        00:00:03 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 nss-user-lookup.target systemd-user-sessions.service time-sync.target ypbind.service

[Service]
EnvironmentFile=/etc/sysconfig/crond
ExecStart=/usr/sbin/crond -n $CRONDARGS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=30s

[Install]
WantedBy=multi-user.target

$ ls -l /usr/sbin/crond
-rwxr-xr-x 1 root root 75712 Mar  6 09:37 /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