免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4593 | 回复: 3
打印 上一主题 下一主题

sun系统crontab任务文件增加过程 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-05-22 16:18 |只看该作者 |倒序浏览
//查看任务文件
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 "$time\t$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

论坛徽章:
0
2 [报告]
发表于 2007-05-22 16:42 |只看该作者
http://www.chinaunix.net/jh/6/271992.html
我过去在写任务文件时,参考了该文件。该文件就是缺少实际例子。

论坛徽章:
0
3 [报告]
发表于 2007-05-22 17:12 |只看该作者
为什么这么麻烦?
定义使用vi编辑器:
EDITOR=vi;export EDITOR
然后直接使用crontab -e,就可以在vi里编辑你的crontab文件了。编辑好后,保存退出,更改会直接生效。可以用crontab -l检查。

论坛徽章:
0
4 [报告]
发表于 2007-05-25 10:17 |只看该作者
原帖由 pondka 于 2007-5-22 17:12 发表
为什么这么麻烦?
定义使用vi编辑器:
EDITOR=vi;export EDITOR
然后直接使用crontab -e,就可以在vi里编辑你的crontab文件了。编辑好后,保存退出,更改会直接生效。可以用crontab -l检查。

就是,这个方法是最简单有效,也不容易出错,步骤也最少。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP