July 24, 2004

cron的使用

  cron来自希腊语的chronos(时间)一词。在linux中,通过运行crontab -e就可以设置在特定的时刻自动运行你指定的程序。每个用户的自动运行程序,都放在/var/spool/cron/目录下,以自己用户名命名的文件中。在这些文件中,每一行都设置一个自动指行的命令,以及其运行的时间。每一行都由7个字段构成,相邻的字段以空格相间,每个字段的含义如下:

FieldMeaning
1Minute (0-59)
2Hour (2-24)
3Day of month (1-31)
4Month (1-12, Jan, Feb, etc)
5Day of week (0-6) 0 = Sunday, 1 = Monday etc or Sun, Mon, etc)
6User that the command will run as
7Command to execute

  其中,有一些设置技巧:
  • 用*/n表示某字段单位时间内运行n次
  • 可以通过以“,”相隔的一列数字,在表示某字段运行的特定值
  • 阿以通过n-m来指定n到m 这个区间
  • 可以用>>logfile 2>&1来将程序运行的输出或错误都写到logfile中
  • >>/dev/null 2>&1可用丢弃程序运行时的输出或错误
  • 可将几个命令以;相隔用()包括起来

参考文献:

Posted by Hilton at July 24, 2004 09:00 PM | TrackBack
Comments

Please check the pages dedicated to... Thanks!!!

Posted by: at December 1, 2004 08:46 PM

The best bitches on the web

Posted by: weak sister bitch at November 13, 2004 04:10 AM

Hour (2-24) should be Hour (0-23)

Posted by: chaoyan at October 22, 2004 02:05 PM

请问一下,我想在每次开机的时候以某一个用户的身份执行一个程序,该用什么方式?用cron可以么?

Posted by: shunz at August 21, 2004 09:12 AM

名气不大的时候,大家还是更关心行业关键词结果了。

Posted by: yeeking at August 16, 2004 03:13 AM

这是Unix和Linux下的必备工具,典型的应用有:非实时的文件备份/服务器监测/数据检查等

Posted by: Peak Jing at July 26, 2004 10:07 PM
Post a comment









Remember personal info?