You are on page 1of 8

linux

LINUX crontab -e vi 0 3 * * 1 /clearigame2 :wq

LINUX cron [ps -ef|grep cron]cron

cron crontabcron table


cron 3
1/var/spool/cron/ root crontab tom crontab
/var/spool/cron/tom
crontab

/etc/crontab crontab

/etc/cron.d/ crontab

crontab /var/adm/cron/ cron.allow cron.deny

1 root crontab
2 cron.allow cron.deny cron.allow crontab root
root crontab
3 cron.allow , cron.deny cron.deny crontab
4 cron.allow cron.deny crontab
cron.allow cron.allow crontab

crontab


minute hour day-of-month month-of-year day-of-week commands
00-59 00-23 01-31 01-12 0-6 (0 is sunday) commands
"*""/""-"","*"/","/5" 5 "-"
,","

:
*****command

1 159 * */1
2 1230 0
3 131
4 112
5 060
6

crontab
# 21:30 apache
30 21 * * * /usr/local/etc/rc.d/lighttpd restart
# 11022
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
# 6 10
10 6 * * * date
#
0 */2 * * * date
# 11 8 8
0 23-7/28 * * * date
# 4 11
0 11 4 * mon-wed date
#1 4
0 4 1 jan * date

10

?
1 # crontab -e
2 * * * * * /bin/date >>/tmp/date.txt
3 * * * * * sleep 10; /bin/date >>/tmp/date.txt
4 * * * * * sleep 20; /bin/date >>/tmp/date.txt
5 * * * * * sleep 30; /bin/date >>/tmp/date.txt
6 * * * * * sleep 40; /bin/date >>/tmp/date.txt
7 * * * * * sleep 50; /bin/date >>/tmp/date.txt

%\
?
1 # backup mysql
2 00 01 * * * mysqldump -u root --password=passwd-d mustang > /root/backups/mustang_$(date +\%Y\%m\%d_\%H\%M\%S).sql
3 01 01 * * * mysqldump -u root --password=passwd-t mustang > /root/backups/mustang-table_$(date +\%Y\%m\%d_\%H\%M\%S).sql

================================================================================

crontab 1
2015 01 27
/home/ a.sh
#!/bin/sh
echo hello > /home/hello.txt
crontab -e
*/1 * * * * /home/a.sh
home hello.txt
2

*/1 * * * * sh /home/a.sh
--------------------------------------------------------------------------------------------
a.sh chmod +x a.sh
/home /home
/home/a.sh
cron /var/log
/1 5
==============================================================================

Linux Crontab 2011-03-21 16:53:14


LINUX
http://edu.codepub.com/2011/0104/28518.php

Linux Linux crontab


Windows ()
/var/spool/cron

/etc/crontab

$ cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

cron SHELL SHELL ( bash shell)PATH


Cron MAILTO MAILTO (MAILTO="")
HOME
/etc/crontab :

minute hour day month dayofweek command

minute - 0 59
hour - 0 23
day - 1 31 ()
month - 1 12 ( Jan Feb )
dayofweek - 0 7 0 7 ( Sun Mon )
command - ( as ls /proc >> /tmp/proc )
root root
run-parts

(*)* month ()
(-) 1-4 1,2,3,4
3,4,6,8
//<interger> 0-59/2 */3

#,

cron ,,,,/etc/cron.d
/etc/crontab

# record the memory usage of the system every monday


# at 3:30AM in the file /tmp/meminfo
30 3 * * mon cat /proc/meminfo >> /tmp/meminfo
# run custom scrpt the first day of every month at 4:10AM
10 4 1 * * /root/scrpts/backup.sh

root crontab crontab /var/spool/cron


crontab crontab -e VISUAL EDITOR
crontab/etc/crontab

0 3 * * * /home/dbbackup/db1backup.sh backup
0 4 * * * /home/dbbackup/db2backup.sh backup

3 /home/dbbackup/db1backup.sh backup4 /home/dbbackup/db2backup.sh backup

*/5 * * * * /home/dbbackup/db2backup.sh backup

crontab /var/spool/cron/username

cron /etc/crontab/etc/cron.d//var/spool/cron
crontab crontab -e /etc/init.d/crond
restart crond /etc/crontab run-
parts /etc/crontab run-parts

************************************************************************************
cron linux Cron Linux

/sbin/service crond start //


/sbin/service crond stop //
/sbin/service crond restart //
/sbin/service crond reload //

/etc/rc.d/rc.local
/sbin/service crond start

Cron Cron

1. crontab

cron crontab cron

crontab -u // cron root


crontab -l // cron
crontab -r // cron
crontab -e // cron

root cron crontab -u root -l


root fred cron crontab -u fred -r
cron crontab -u root -e
vi */1 * * * * ls >> /tmp/ls.txt

(0-59)
(0-23)
(1-31)
(1-12)
(0-6) //0

"*""/""-"","*"/","*/5" 5
"-",","

6
-----------------
0 6 * * * echo "Good morning." >> /tmp/test.txt // echo cron email
root

-----------------
0 */2 * * * echo "Have a break now." >> /tmp/test.txt

11 8
-----------------
" >> /tmp/test.txt
0 23-7/28 * * * echo "Have a good dream

4 11
-----------------
0 11 4 * 1-3 command line

1 1 4
-----------------
0 4 1 1 * command line

cron cron /var/spool/cron cron


crontab -e cron
cron

2./etc/crontab cron

cron /var/spool/cron /etc/crontab cron


crontab /etc/crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root //
HOME=/ //,
# run-parts
01 * * * * root run-parts /etc/cron.hourly ///etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily ///etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly ///etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly ///etc/cron.monthly

"run-parts"
************************************************************************************

crontab
at linux cron (crond) Linux
, Linux
:crontab
crond
crond linux windows
crond crond

Linux
/etc crontab

/etc/crontab
[root@localhost ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""HOME=/

# run-parts
51 * * * * root run-parts /etc/cron.hourly
24 7 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
[root@localhost ~]#

crond SHELL shell bash PATH


MAILTO crond root MAILTO
HOME

crontab
crontab /var/spool/cron

/etc/cron.deny

crontab

/etc/cron.allow

crontab

/var/spool/cron/

crontab ,

crontab
crontab

minute hour day month week command

minute 0 59
hour 0 23
day 1 31
month 1 12
week 0 7 0 7
command

* month
,1,2,5,7,8,9
-2-62,3,4,5,6
/0-23/2*/10 minute

crond
crontab
yum install crontabs

/sbin/service crond start //


/sbin/service crond stop //
/sbin/service crond restart //
/sbin/service crond reload //
crontab
service crond status
crontab
service crond start
crontab
ntsysv

chkconfig level 35 crond on

crontab
1
crontab [-u user] file
crontab [-u user] [ -e | -l | -r ]
2
crontab shell script

3
-u user crontab -u ixdba ixdba crontab root
filefile , file crontab crontabcrontab
crontab
-e crontab crontab
-l crontab crontab
-r/var/spool/cron crontab crontab
-i crontab
4
1). crontab

cron crontab EDITORcron


crontab 9 9 % UNIX LINUX vi$ HOME . profile
EDITOR=vi; export EDITOR
<user> cron <user> davecron
# (put your own initials here)echo the date to the console every
# 15minutes between 6pm and 6am
0,15,30,45 18-06 * * * /bin/echo 'date' > /dev/console
5
1 5
tty1 crontab
cron
$ crontab davecron
cron 1 5
/var/spool/cron ( dave)
2). crontab
crontab
$ crontab -l
0,15,30,45,18-06 * * * /bin/echo `date` > dev/tty1
$ H O M E crontab
$ crontab -l > $HOME/mycron
crontab
3). crontab
crontab E D I TO R v i v i crontab

$ crontab -e
v i crontab c r o n

crontab
# DT:delete core files,at 3.30am on 1,7,14,21,26,26 days of each month
30 3 1,7,14,21,26 * * /bin/find -name "core' -exec rm {} \;
crontab

crontab -l
$ crontab -l
# (crondave installed on Tue May 4 13:07:43 1999)
# DT:ech the date to the console every 30 minites
0,15,30,45 18-06 * * * /bin/echo `date` > /dev/tty1
# DT:delete core files,at 3.30am on 1,7,14,21,26,26 days of each month
30 3 1,7,14,21,26 * * /bin/find -name "core' -exec rm {} \;
4). crontab
crontab
$ crontab -r
5). crontab
crontab $ H O M E /var/spool/cron/<username>
<username>
$ crontab <filename>
<filename>$ H O M E
$ H O M E crontab r e
crontab
crontab crontab crontab
delete <Ctrl-D> crontab
5
1 1 command

* * * * * command

2 3 15

3,15 * * * * command

3 8 11 3 15

3,15 8-11 * * * command

4 8 11 3 15

3,15 8-11 */2 * * command

5 8 11 3 15

3,15 8-11 * * 1 command

6 21:30 smb

30 21 * * * /etc/init.d/smb restart

7 11022 4 : 45 smb

45 4 1,10,22 * * /etc/init.d/smb restart

8 1 : 10 smb

10 1 * * 6,0 /etc/init.d/smb restart

9 18 : 00 23 : 00 30 smb

0,30 18-23 * * * /etc/init.d/smb restart

10 11 : 00 pm smb

0 23 * * 6 /etc/init.d/smb restart

11 smb

* */1 * * * /etc/init.d/smb restart

12 11 7 smb

* 23-7/1 * * * /etc/init.d/smb restart

13 4 11 smb

0 11 4 * mon-wed /etc/init.d/smb restart

14 4 smb

0 4 1 jan * /etc/init.d/smb restart

15/etc/cron.hourly

01 * * * * root run-parts /etc/cron.hourly



run-parts

1.
crontab crontab

crontab shell
crontab

cron shelll
3
1
2 java source
cat start_cbp.sh
#!/bin/sh
source /etc/profile
export RUN_CONF=/home/d139/conf/platform/cbp/cbp_jboss.conf
/usr/local/jboss-4.0.5/bin/run.sh -c mev &
3 OK crontab crontab

0 * * * * . /etc/profile;/bin/sh /var/www/java/audit_no_count/bin/restart_audit.sh

2.

crontab
0 */3 * * * /usr/local/apache2/apachectl restart >/dev/null 2>&1
/dev/null 2>&1/dev/null/dev/null
/dev/null

3.

root crontab uroot e/etc/crontab


/etc/crontab root

4.
cron job 2 cron
crontab /etc/init.d/crond restart job / tail -f /var/log/cron
crontab -r Crontab /var/spool/cron Crontab crontab
crontab %\% date +%Y%m%d crontab
date +\%Y\%m\%d