Page 80 - RHEL8 BOOK
P. 80

Job Scheduling using crontab
          we can schedule and run tasks in the background automatically at regular intervals using
          Crontab command. Crontab executes jobs automatically in backend on specified time interval.

          Running the Crond Service:
          Step 1: To run the crond service in the current session, type the following command as root:
          [root@sun ~]# systemctl start crond

          Step 2: To configure the service to be automatically started at boot time, use the following command:
          [root@sun ~]# systemctl enable crond

          Step 3: To stop the crond service, run the following command as root:
          [root@sun ~]# systemctl stop crond

          Step 4: To check the status of crond service, run the following command as root:
          [root@sun ~]# systemctl status crond

          Configuring cron jobs:
          Step 5: The configuration file for cron jobs is the /etc/crontab. The file contains the following:
          [root@sun ~]# vi /etc/crontab

          SHELL=/bin/bash
          PATH=/sbin:/bin:/usr/sbin:/usr/bin
          MAILTO=root
          HOME=/
          # For details see man 4 crontabs
          # Example of job definition:
          # .---------------- minute (0 - 59)
          # | .------------- hour (0 - 23)
          # | | .---------- day of month (1 - 31)
          # | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
          # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
          # | | | | |
          # * * * * * username  command to be executed
          15 11 * * * root reboot

          Step 6: To add or edit job in crontab, use following command:
          [root@sun ~]# crontab –e

          Step 7: To edit other users crontab use command as below:
          [root@sun ~]# crontab -u username -e
          [root@sun ~]# crontab -u mohit –e

           List Scheduled Cron Jobs:
          Step 8: To view cron jobs of current user use following command:.
          [root@sun ~]#  crontab –l

          Step 9: To view cron jobs of other user use following command:
          [root@sun ~]#  crontab -u username –l



                                                       S. Pradhan
                             (MCA, MBA-IT, BCA, CCNA, MCSA 2012, RHCE, ETHICAL HACKING)
                                             Email Id:-spradhan.iiht@gmail.com
                                                           80
   75   76   77   78   79   80   81   82   83   84   85