shell放入计划日志的问题!!!
我写了个shell脚本获取服务器的一些实时属性,比如cpu的使用率。top -n1获取的。
我把脚本执行写入计划日志crontab里,发现显示的数据跟我手动执行脚本不一样。
把top改成/usr/bin/top还是一样的。
求解释!!!
我把脚本执行写入计划日志crontab里,发现显示的数据跟我手动执行脚本不一样。
把top改成/usr/bin/top还是一样的。
求解释!!!
作者: xiangliangyu2008 发布时间: 2011-05-31
加-b参数
/usr/bin/top -n1 -b
/usr/bin/top -n1 -b
作者: steptodream 发布时间: 2011-05-31
-b : Batch mode operation
Starts top in 'Batch mode', which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the '-n' command-line option or until killed.
Starts top in 'Batch mode', which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the '-n' command-line option or until killed.
作者: steptodream 发布时间: 2011-05-31
是的,top我能弄出来,但是sar -n DEV 1 1好像不可以,而且里面获取mysql的一些数值需要登录,手动执行脚本可以,crontab一执行就是空值,里面怎么运行的还是不清楚,主席指导下!
作者: xiangliangyu2008 发布时间: 2011-05-31
问题里说的是top 现在又变sar了 那你问的时候咋不说sar?
我的系统里没有sar 自己去看帮助文档man sar
我的系统里没有sar 自己去看帮助文档man sar
作者: steptodream 发布时间: 2011-05-31
环境变量的问题吧
脚本首行加
. ~/.bash_profile
脚本首行加
. ~/.bash_profile
作者: justkk 发布时间: 2011-05-31
基本解决了,谢谢各位,小结下:
1.环境变量问题,可以首行加 source ~/.bash_profile,也可以which下命令替换进去
2.有部分命令跟环境变量无关,是时间导致的,具体还在摸索,可以显示每个输出进行比较。top可以按照主席说的,sar的输出有变化,位置变了,所以输出来就什么都明白了
3.待续...
1.环境变量问题,可以首行加 source ~/.bash_profile,也可以which下命令替换进去
2.有部分命令跟环境变量无关,是时间导致的,具体还在摸索,可以显示每个输出进行比较。top可以按照主席说的,sar的输出有变化,位置变了,所以输出来就什么都明白了
3.待续...
作者: xiangliangyu2008 发布时间: 2011-05-31
我一般添加计划任务都是添加到/etc/crontab 这个文件前面本来就有一些环境变量 比如
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
所以常用的命令 一般直接写是没问题的。
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
所以常用的命令 一般直接写是没问题的。
作者: steptodream 发布时间: 2011-05-31