ITPub博客

首页 > 应用开发 > IT综合 > crontab任务文件的建立过程

crontab任务文件的建立过程

原创 IT综合 作者:13799314345 时间:2007-05-22 16:47:54 0 删除 编辑

//查看任务文件
crontab -l
//备份任务文件
crontab -l > /crontabrootfile
//查看保存用户crontab到一个文件
more /crontabrootfile
cd /var/log
ls -al
//在/var/log/建system目录
mkdir /var/log/system
ls -al
cd system
//在/var/log/system/下建system_monitor文件
vi system_monitor
#!/bin/sh
#sh /.profile
day=`date +%m%d%Y`
file="/var/log/system/sysinfo$day"
if [ -f $file ]; then
echo "ok">/dev/null
else
echo " date cpu mem swap load average oracle sessions">>$file
echo " user system idle free free 1 5 15">>$file
echo "">>$file
fi
time=`date '+%m%d %H:%M:%S '`
load=`uptime |grep load|sed s/,//g|awk '{printf"%10s %6s %6s", $10,$11,$12}'`
#cpu=`vmstat |grep -v [cpu][swap]|awk '{printf "%8s %6s %9s", $20,$21,$22}'`
cpu=`vmstat 1 2 | sed -n '$p' |awk '{printf "%8s %6s %9s", $20,$21,$22}'`
real=`vmstat |grep -v [cpu][swap]|awk '{printf "%12s %10s",$5,$4}'`
httpd_number=`ps -ef|grep httpd|grep -v grep|wc -l|awk '{printf "%9d",$1}'`
oracle_number=`ps -ef|grep "LOCAL="|grep -v grep|wc -l|awk '{printf "%9d",$1}'`
echo "$timet$cpu$real$load$oracle_number" >>$file

//查看新建文件属性
ls -al
total 2
drwxr-xr-x 2 root other 512 May 22 15:53 .
drwxr-xr-x 3 root sys 512 May 22 15:51 ..
-rw-r--r-- 1 root other 909 May 22 15:53 system_monitor
//修改文件属性
chmod +x system_monitor
//查看修改后的新建文件属性
ls -al
total 2
drwxr-xr-x 2 root other 512 May 22 15:53 .
drwxr-xr-x 3 root sys 512 May 22 15:51 ..
-rwxr-xr-x 1 root other 909 May 22 15:53 system_monitor
//查看旧的任务信息
crontab -l
crontab -l>tmp
more tmp
//在上一行开始加入新文本 O
//在下一行开始加入新文本 o
//0,5,10,15,20,25,30,35,40,45,50,55 * * * * /var/log/system/system_monitor&
//保存退出
vi tmp
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /var/log/system/system_monitor&
//查看修改好后的任务信息
more tmp
//将新修改的配置任务信息推回crontab
crontab tmp
//查看新的任务信息
crontab -l
//过5分钟后查看/var/log/system/,如果有sysinfo05222007类似文件生成,说明已经增加新的任务。
ls -al
total 6
drwxr-xr-x 2 root other 512 May 22 16:05 .
drwxr-xr-x 3 root sys 512 May 22 15:51 ..
-rw-r--r-- 1 root other 294 May 22 16:05 sysinfo05222007
-rwxr-xr-x 1 root other 909 May 22 15:53 system_monitor
-rw-r--r-- 1 root other 556 May 22 16:01 tmp

//如果想要修改crontab,一般做以下的几步就可以了
//将crontab 推到一个自定义的文件上
//crontab -l> tmp
//编辑这个文件,做需要的修改
//vi tmp
//推回crontab
//crontab tmp

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/369836/viewspace-915884/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论
  • 博文量
    1
  • 访问量
    3072