Live as if you were to die tomorrow. Learn as if you were to live forever.

Friday 13 March 2015

Examples of cron job


1.       Set a cron job that will be run at 4:30 am on the 1st and 15th of each month and should execute on every Friday.

30           4              1,15        *             5              command/script

2.       Set a cron job that will run at 1:30 on first day of every month

30           2              1              *             *             command/script

3.       Set a cron that will run at 18:45 on every Friday, but every 3rd month i.e every Fri in Jan, Apr,...

45           18           *             */3         5              command/script

4.       Explain the below cron job

23             0-23/2     *            *          *            command/Script

Above cron will run at 23 mins after midnight, 2 am, 4am, 6am…. everyday.

5.       Explain the blow cron job

5              4              *             *             sun         command/script
It will execute at 4:05am on every Sunday.

6.       Explain the blow cron job

20   1   *   *  *   find /tmp -atime +3 -exec  rm -i {} ';'

Run at 1:20 am each morning and removes all files in the /tmp dir that have not been accessed in 3 days.

7.       Explain below command

1        0       *       *     *                                                                                                            
\ cd /tmp; find . ! -name lost+found -type -d -mtime +3 -exec rm -f {} ';'

At one past midnight, everyday, remove all subdirectories of /tmp which have not been accessed from last 72 hrs but don’t remove the directory lost+found in /tmp.

8.       Where would you find the crontab file for user pramod?

/var/spool/cron/pramod is the crontab file for user pramod

9.       What command is used to modify the crontab?

crontab -e

10.   What command is used to modify the crontab for use pramod?
crontab -e -u pramod

11.   What command is used to list the crontab?
crontab -l

12.   What command is used to list the crontab of the user pramod?
crontab -l -u pramod

13.   What command is used to delete the crontab?
crontab -r

14.   What command is used to delete the crontab of the user pramod?
crontab -r -u pramod

15.   How would you prevent user pramod from creating his own personal crontab file ?

Add the entry of user in file /etc/cron.deny

No comments:

Post a Comment