Chinaunix
标题:
写的流量监控脚本,只能手动执行,不能任务执行
[打印本页]
作者:
killed000
时间:
2012-10-27 22:28
标题:
写的流量监控脚本,只能手动执行,不能任务执行
流量统计脚本如下
#!/bin/bash
DAT=`date "+%m%d"`
time_stamp=`date "+%m/%d/%T"`
eth=eth0
while : ; do
RXpre=$(ifconfig ${eth} | grep bytes | awk '{print $2}'| awk -F":" '{print $2}')
TXpre=$(ifconfig ${eth} | grep bytes | awk '{print $6}' | awk -F":" '{print $2}')
sleep 1
RXnext=$(ifconfig ${eth} | grep bytes | awk '{print $2}'| awk -F":" '{print $2}')
TXnext=$(ifconfig ${eth} | grep bytes | awk '{print $6}' | awk -F":" '{print $2}')
echo "$time_stamp,$(((${RXnext}-${RXpre})/1024))KB/s,$(((${TXnext}-${TXpre})/1024))KB/s">>/tmp/network_status_$DAT.csv
done
手动执行 ./network.sh 可以正常看到 /tmp/下有一个 network_status_1022.csv文件,
但是放入crontab 中就不会执行,计划任务如下写的。
*/10 0-23 * * * /root/monitor/linkmon.sh
不知道为啥?
作者:
Shell_HAT
时间:
2012-10-27 22:46
*/10 0-23 * * * /root/monitor/linkmon.sh >/tmp/test.log 2>&1
复制代码
看看日志
作者:
killed000
时间:
2012-10-27 23:37
谢谢楼上的,日志提示 ifconfig 居然不能运行,先加一个 /sbin/ifconfig吧
作者:
飞奔的兔子
时间:
2013-03-15 13:55
哥们 你那个流量监控的脚步可以给我说一个完整的么 我这边没实现啊 你的帖子我看到了 还是不行
作者:
pix77
时间:
2013-03-15 14:58
用mail也能看到报错
作者:
Shell_HAT
时间:
2013-03-15 15:04
回复
4#
飞奔的兔子
报错信息贴出来看看
作者:
飞奔的兔子
时间:
2013-03-15 15:15
我运行lz的那些脚步代码了,没有生成报告,另外脚步一直在运行没报错
回复
6#
Shell_HAT
作者:
Shell_HAT
时间:
2013-03-15 15:59
回复
7#
飞奔的兔子
ifconfig eth0
ifconfig eth0 | grep bytes
ifconfig eth0 | grep bytes | awk '{print $2}'
ifconfig eth0 | grep bytes | awk '{print $2}'| awk -F":" '{print $2}'
复制代码
看看哪一步出的问题
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2