分类: LINUX
2011-10-13 11:14:06
crontab -e 进入crontab 输入定时执行
加入 crontab */1分 *时 *日 *月 *星期 /etc/log.sh
log.sh脚本如:
#!/bin/bash
cd /root
if [ -f "hostlog.log" ];then
rm -f hostlog.log
rm -f hostlogtosoc.log
fi
touch hostlog.log
df -h >>hostlog.log
free >>hostlog.log
#top -b -n 1 | grep Mem >>hostlog.log
top -b -n 1 | grep Cpu >>hostlog.log
awk 'NR==2{print "Disk Size:"$2 " Used:"$3 " Avail:"$4 " Used%:"$5 " Mound On:"$6} NR==3{print "Disk Size:"$2 "
Used:"$3 " Avail:"$4 " Used%:"$5 " Mound On:"$6} NR==6{print "Mem Total:"$2 " Used:"$3 " Free:"$4 " Buffers:"$6 "
Cached:"$7} NR==9{print "Cpu Used:"$2 " System:"$3 " Idle:"$5 " Wait"$6} ' hostlog.log >hostlogtosoc.log
logger -f hostlogtosoc.log
#rm -f hostlog.log
记得给脚本加x 执行权。
crontab -r : 删除目前的时程表
crontab -l : 列出目前的时程表
重启/etc/init.d/cront restart