Start / stop / restart / status check of cron, cron execution log

Explains how to start / stop / restart / check the status of cron.

Cron is a server that automatically executes jobs on a regular basis.

Check the status of cron

To check the status of cron, use "status" of the systemctl command.

sudo systemctl status cron
If it is running

If it is running, the following will be displayed.

● cron.service --Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2020-05-12 11:51:51 JST; 1 weeks 0 days ago
     Docs: man: cron (8)
 Main PID: 1349 (cron)
    Tasks: 1 (limit: 9479)
   CGroup: /system.slice/cron.service
           mq1349 / usr / sbin / cron -f

May 20 07:17:01 development-batch CRON [88341]: pam_unix (cron: session): session closed for user root
May 20 08:17:01 development-batch CRON [92378]: pam_unix (cron: session): session opened for user root by (uid = 0)
May 20 08:17:01 development-batch CRON [92379]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
May 20 08:17:01 development-batch CRON [92378]: pam_unix (cron: session): session closed for user root
May 20 09:17:01 development-batch CRON [96646]: pam_unix (cron: session): session opened for user root by (uid = 0)
May 20 09:17:01 development-batch CRON [96647]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
May 20 09:17:01 development-batch CRON [96646]: pam_unix (cron: session): session closed for user root
May 20 10:17:01 development-batch CRON [100899]: pam_unix (cron: session): session opened for user root by (uid = 0)
May 20 10:17:01 development-batch CRON [100900]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
May 20 10:17:01 development-batch CRON [100899]: pam_unix (cron: session): session closed for user root
When stopped

If it is stopped, the following will be displayed.

● cron.service --Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Wed 2020-05-20 11:04:56 JST; 1min 22s ago
     Docs: man: cron (8)
  Process: 1349 ExecStart = / usr / sbin / cron -f $EXTRA_OPTS (code = killed, signal = TERM)
 Main PID: 1349 (code = killed, signal = TERM)

May 20 08:17:01 development-batch CRON [92379]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
May 20 08:17:01 development-batch CRON [92378]: pam_unix (cron: session): session closed for user root
May 20 09:17:01 development-batch CRON [96646]: pam_unix (cron: session): session opened for user root by (uid = 0)
May 20 09:17:01 development-batch CRON [96647]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
May 20 09:17:01 development-batch CRON [96646]: pam_unix (cron: session): session closed for user root
May 20 10:17:01 development-batch CRON [100899]: pam_unix (cron: session): session opened for user root by (uid = 0)
May 20 10:17:01 development-batch CRON [100900]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
May 20 10:17:01 development-batch CRON [100899]: pam_unix (cron: session): session closed for user root
May 20 11:04:56 development-batch systemd [1]: Stopping Regular background program processing daemon ...
May 20 11:04:56 development-batch systemd [1]: Stopped Regular background program processing daemon.

Start cron

Start cron using the systemctl command "start". Run with root privileges using the sudo command.

sudo systemctl start cron

Even if the boot is successful, the message that it was successful is not returned. Please check the status.

Stop cron

To stop cron, use the systemctl command "stop". Run with root privileges using the sudo command.

sudo systemctl stop cron

If the outage is successful, no successful message will be returned. Please check the status.

Restart cron

To restart cron, use the systemctl command "restart". Run with root privileges using the sudo command.

sudo systemctl restart cron

restart simply executes the stop command and executes the start command. Normally, use the reload command as it will disconnect the processing from the HTTP client.

If the reboot is successful, you will not get a successful message. Please check the status.

To see the cron execution log

Servers such as cron are centrally managed by a program called systemd.

The cron start / stop log is output to the systemd log.

Use the journalctl command to see the systemd logs. Specify the unit "cron" with the "-u" option. Please note that you cannot see the cron log unless you run it with sudo. If you want to see only the last part of the log, combine the "-r" option.

sudo journalctl -r -u cron

This is a sample log.

Jul 23 14:40:03 shinshina-development-app-00000001 CRON [35501]: pam_unix (cron: session): session closed for user myapp
Jul 23 14:40:01 shinshina-development-app-00000001 CRON [35502]: (myapp) CMD ($HOME / $SDIR / customer / osasoi_many_view_bukken.pl)
Jul 23 14:40:01 shinshina-development-app-00000001 CRON [35501]: pam_unix (cron: session): session opened for user myapp by (uid = 0)
Jul 23 14:39:01 shinshina-development-app-00000001 CRON [35409]: pam_unix (cron: session): session closed for user root
Jul 23 14:39:01 shinshina-development-app-00000001 CRON [35410]: (root) CMD ([-x / usr / lib / php / sessionclean] && if [! -d / run / systemd / system]; then / usr / lib / php / sessionclean; fi)
Jul 23 14:39:01 shinshina-development-app-00000001 CRON [35409]: pam_unix (cron: session): session opened for user root by (uid = 0)
Jul 23 14:35:37 shinshina-development-app-00000001 CRON [35332]: pam_unix (cron: session): session closed for user myapp
Jul 23 14:35:05 shinshina-development-app-00000001 CRON [35331]: pam_unix (cron: session): session closed for user myapp
Jul 23 14:35:05 shinshina-development-app-00000001 CRON [35330]: pam_unix (cron: session): session closed for user myapp
Jul 23 14:35:01 shinshina-development-app-00000001 CRON [35329]: pam_unix (cron: session): session closed for user root
Jul 23 14:35:01 shinshina-development-app-00000001 CRON [35336]: (myapp) CMD ($HOME / $SDIR / customer / oshirase_osusume_bukken.pl)

You can check the automatically executed jobs.

cron configuration file

I will explain the cron configuration file in another article.

Associated Information