Table of Contents

Home tmade.de

Home Wiki

Cronjobs

For all users:

/etc/cron.d/cronjobname

Configuration (SLES):

/etc/sysconfig/cron

Crontab files (created via “crontab -e”) are located in:

/var/spool/cron/tabs

Example:

SLES10:/etc/cron.d # ll
total 8
-rw-r--r-- 1 root     root  151 Mar  9 14:58 root_crontest
-rw-r--r-- 1 testuser users  61 Mar  9 14:58 testuser_crontest
SLES10:/etc/cron.d # cat root_crontest
  */1 * * * * root /bin/logger "testmessage"
  */1 * * * * root /usr/sbin/ntpdate -s time.server.com && /sbin/hwclock --systohc
  */1 * * * * root /usr/bin/echo "hello world"
SLES10:/etc/cron.d # cat testuser_crontest
  */5 * * * * testuser echo "hello testuser"

SLES11:

  */20 * * * * root /usr/sbin/sntp -P no -r time.server.com && /sbin/hwclock --systohc 2>> /dev/null
SLES10::/etc/cron.d # cat tmade
*/1 * * * * testuser echo "hallo world" > /home/testuser/testfile

Enter a cronjob as user “testuser”:

crontab -e                                                                      #Add and create a crontab (as logged in user)
crontab -l                                                                      #List cronjobs (as logged in user)

Overview Syntax

*     *   *   *    *  command to be executed
-     -    -    -    -
|     |     |     |     |
|     |     |     |     +----- day of week (0 - 6) (Sunday=0)
|     |     |     +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

Predefined scheduling definitions

There are several special predefined values which can be used to substitute the CRON expression.
Entry 	                Description 	                                Equivalent To
@yearly (or @annually) 	Run once a year, midnight, Jan. 1 	        0 0 1 1 *
@monthly 	        Run once a month, midnight, first of month 	0 0 1 * *
@weekly 	        Run once a week, midnight on Sun 	        0 0 * * 0
@daily 	                Run once a day, midnight 	                0 0 * * *
@hourly 	        Run once an hour, beginning of hour 	        0 * * * *
@reboot 	        Run at startup 	

Examples

30 18 * * *   /sbin/shutdown -r now                                           #Shutdown at 18:30h
15 0-22/2 * * *   /home/test                                                  #Every 2 hours + 15 min. (0:15, 2:15)
@reboot /etc/init.d/postfix start                                             #Runs just on reboot

Explication:

min hour day/month month day/week Execution time

30 0 1 1,6,12 * --                                                            #00:30 Hrs  on 1st of Jan, June & Dec. 
0 20 * 10 1-5 --                                                              #8.00 PM every weekday (Mon-Fri) only in Oct. 
0 0 1,10,15 * * --                                                            #Midnight on 1st ,10th & 15th of month 
5,10 0 10 * 1 --                                                              #At 12.05,12.10 every Monday & on 10th of every month 
*/5   *   * * *    /usr/bin/message.sh                                        #Every 5 minutes
*/20 * * * * /usr/sbin/ntpdate –s time.server.test                            #Sync timeserver each 20 minutes
0 */2 * * *  /usr/sbin/ntpdate –s time.server.test                            #Run all 2 hours
0 * * * *    /usr/sbin/ntpdate –s time.server.test                            #Run every hour

AT

Schedule:

at hh:mm
finger >> /var/log/messages		//exit with ctrl+D
at noon tomorrow
finger >> /var/log/messages		//exit with ctrl+D

check:

atq oder at -l

remove:

atrm job_number				//check if remove with atq
linux/cronjobs.txt · Last modified: 2019/10/01 09:38 by tmade
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki