收藏本站 收藏本站
积木网首页 - 软件测试 - 常用手册 - 站长工具 - 技术社区
首页 > shell编程 > 正文

首页 - PHP - 数据库 - 操作系统 - 游戏开发 - JS - Android - MySql - Redis - MongoDB - Win8 - Shell编程 - DOS命令 - jQuery - CSS样式 - Python - Perl

Access - Oracle - DB2 - SQLServer - MsSql2008 - MsSql2005 - Sqlite - PostgreSQL - node.js - extjs - JavaScript vbs - Powershell - Ruby

浅谈:linux cron 计划任务常用符号小结

[root@wx-a ~]# crontab --help
crontab: invalid option -- '-'
crontab: usage error: unrecognized option
usage: crontab [-u user] file
crontab [-u user] [ -e | -l | -r ]
(default operation is replace, per 1003.2)
-e (edit user's crontab) 编辑crontab 工作内容
-l (list user's crontab) 查看crontab工作内容
-r (delete user's crontab) 删除所有的crontab任务
-i (prompt before deleting user's crontab)
-s (selinux context)

默认情况下,任何用户只要不被列入/etc/cron.deny 当中,都可以执行”crontab ?e” 去编辑自己的例行性命令了,

代表的意义

分钟

小时

日期

月份

数字范围

0-59

0-23

1-31

1-12

0-7


周的数字为0-7时,都代表”星期天”的意思,

辅助字符

特殊字符

代表意义

*(星号)

代表任何时刻都接受的意思,

,(逗号)

代表分割时段的意思,如果要执行2:00与4:00时,

0 2,4 * * * command

时间参数有五列,第二列就是2,4 代表2:00 与4:00

-(减号)

代表一段时间的范围,例如7点到10点之间的每小时10分钟都进行一次

工作: 10 7-10 * * * command

第二列变成7-10 代表7 8 9 10

/n(斜线)

那个n代表数字,即是每隔n单位间隔的意思,例如每5分钟进行一次,

则: */5 * * * * command

也可以写成0-59/5 意思相同

系统任务计划

[root@wx-a ~]# cat /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
# | | | | |
# * * * * * user-name command to be executed

crontab -e是针对用户的cron来设计的。

基本上cron这个服务的最低检测限制是”分钟”,所以cron每分钟去读取一次/etc/crontab 与/var/spool/cron 里面的数据内容。

标准输出(stout): 代码为1 使用>或>>

标准错误输出(stderr): 代码为2 使用2> 或2>>

黑洞/dev/null

错误输出 2>&1

cron 让计划任务不在屏幕上输出采用 > /dev/null 2>&1

[root@wx-a ~]# crontab -l
*/1 * * * * echo "hello" >> /tmp/test.txt
[root@wx-a ~]# cat /tmp/test.txt
hello
[root@wx-a ~]# cat /tmp/test.txt
hello
hello

让输出到黑洞里面去

[root@wx-a ~]# crontab -l
*/1 * * * * echo "hello"
[root@wx-a ~]# crontab -l
*/1 * * * * echo "hello" >/dev/null 2>&1 输出到黑洞了

其他的帮助可以查看 man cron 或者man crontab

ps:ocsng linux客户端安装

aptitude -y install gcc automake autoconf libtool make
aptitude -y install dmidecode libxml-simple-perl libcompress-zlib-perl libnet-ip-perl libwww-perl libdigest-md5-perl libnet-ssleay-perl
aptitude -y install libcrypt-ssleay-perl libnet-snmp-perl libproc-pid-file-perl libproc-daemon-perl net-tools libsys-syslog-perl pciutils smartmontools read-edid nmap
tar ?xvzf Ocsinventory-Agent-2.0.x.tar.gz
cd Ocsinventory-Agent-2.0.x
env PERL_AUTOINSTALL=1 perl Makefile.PL
make
make install

Linux/Nginx如何查看搜索引擎蜘蛛爬虫的行为
摘要做好网站SEO优化的第一步就是首先让蜘蛛爬虫经常来你的网站进行光顾,下面的Linux命令可以让你清楚的知道蜘蛛的爬行情况。下面我们针对nginx服

Linux Shell脚本面试25问集合
Q:1Shell脚本是什么、它是必需的吗答:一个Shell脚本是一个文本文件,包含一个或多个命令。作为系统管理员,我们经常需要使用多个命令来完成一项任务

iredmail下安装脚本分析(一)---get_all.sh 文件所在目录为PKGS
iredmail是一套以postfix为核心的整合邮件系统的安装脚本,可以达到快速部署邮件服务器的目的。经过上面的一系列分析后,进入到获取安装包的步骤,

本周排行

更新排行

强悍的草根IT技术社区,这里应该有您想要的!
Copyright © 2010 Gimoo.Net. All Rights Rreserved  京ICP备05050695号