linux定时任务
/root/monitor.sh文件内容如下:
#!/bin/bash function check(){ echo "------------时间:`date`---------" echo "内存使用情况:" free -m echo "cpu使用情况" top -n 1 | head -4 echo "CPU占用最多的前10个进程:" ps auxw |head -1;ps auxw |sort -rn -k3 |head -10 echo "内存消耗最多的前10个进程:" ps auxw|head -1;ps auxw|sort -rn -k4|head -10 echo "虚拟内存使用最多的前10个进程:" ps auxw|head -1;ps auxw|sort -rn -k5|head -10 echo "打开文件句柄数最多的10个进程:" echo "数量 PID CMD" for i in `/usr/sbin/lsof -n | awk '{print $2}' | sort | uniq -c | sort -nr |head -10 |tr -s [:space:] |sed 's/^[ ]*//g' |sed 's/[[:space:]]/;/g'` do num=`echo $i |awk -F';' '{print $1}'` pid=`echo $i |awk -F';' '{print $2}'` echo -n "${num} " echo `ps -eo pid,cmd |grep -v grep |grep $pid` done echo "当前网络连接数:" /usr/bin/netstat -an | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' echo "-------------done----------------" } check
[root@localhost /var/spool/cron] crontab -u root -l
*/1 * * * * /etc/rc.d/tc.sh
#59 * * * * (cd /root/ && ./clear_vm_cached.sh >> clear_vm_cached.log) >/dev/null 2>&1
40 1 * * * /root/apps/fudata_config_backup/backup_patient_portrait.sh >/dev/null 2>&1
1 1 * * * find /data/mysql -type f -name "mysql-bin.00*" -mtime +60 -delete
30 0 * * * /data/apps/clear_log/clear_tars_log.sh
* * * * * (/usr/bin/bash /root/monitor.sh >> /data1/log/monitor.log) >/dev/null 2>&1