CT320

CT320: Network and System Administration

Fall 2017

Periodic

See this page as a slide show

CT 320: Network and System Administration

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
   1814 ?        00:00:00 atd
   1081 ?        00:00:17 chronyd
   1806 ?        00:01:18 crond
   6442 ?        00:00:00 gvfsd
    209 ?        00:00:00 kaluad
     98 ?        00:00:00 kauditd
    107 ?        00:00:00 kblockd
    104 ?        00:00:56 khugepaged
     99 ?        00:00:04 khungtaskd
    106 ?        00:00:00 kintegrityd
    208 ?        00:00:00 kmpath_rdacd
    103 ?        00:00:00 ksmd
   1100 ?        00:01:03 ksmtuned
      2 ?        00:00:04 kthreadd
    197 ?        00:00:00 kthrotld
1457968 ?        00:00:00 kworker/0:4H-kblockd
 424143 ?        00:00:00 kworker/11:0H-kblockd
1445549 ?        00:00:00 kworker/2:7H-kblockd
1412151 ?        00:00:00 kworker/3:1H-kblockd
 880692 ?        00:00:00 kworker/4:0H-kblockd
2870995 ?        00:00:00 kworker/5:0H-kblockd
2036758 ?        00:00:00 kworker/6:0H-kblockd
2604732 ?        00:00:26 kworker/7:0H-kblockd
1999113 ?        00:00:12 kworker/8:8H-kblockd
1420807 ?        00:00:08 kworker/9:3H-kblockd
1308614 ?        00:00:00 kworker/u24:0-nfsiod
1439735 ?        00:00:00 kworker/u24:2-xprtiod
1378172 ?        00:00:00 kworker/u24:3-nfsiod
1458029 ?        00:00:00 kworker/u24:4-nfsiod
   1851 ?        00:00:00 lockd
   1035 ?        00:00:04 lsmd
    112 ?        00:00:00 md
   1836 ?        00:00:00 nfsiod
   1668 ?        00:08:06 pmcd
   1069 ?        00:11:14 polkitd
     14 ?        00:11:46 rcu_sched
   1394 ?        00:00:00 rhsmcertd
   1028 ?        00:00:15 rpcbind
   1041 ?        00:00:00 rpciod
   1396 ?        00:00:01 rpc.statd
   1390 ?        00:07:50 rsyslogd
   1383 ?        00:00:00 sshd
      1 ?        00:56:04 systemd
   1783 ?        00:12:50 systemd-logind
    689 ?        00:03:31 systemd-udevd
   1384 ?        01:24:05 tuned
   1781 ?        00:01:39 /usr/sbin/httpd
    115 ?        00:00:00 watchdogd
   1042 ?        00:00:00 xprtiod
   1133 ?        00:00:13 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 Apr  6  2024 /usr/sbin/crond


Is crond SUID? How does it execute your crontab as you?

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

Modified: 2017-09-12T10:38

User: Guest

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building