(1)编写一个脚本
vi clean_host.sh
#!/bin/bash pid_cpu=`ps aux|grep -v PID|sort -nr -k3|head -n1 | awk '{print $2,$3,$11}'` pid=`echo $pid_cpu |awk '{print $1}'` cpu=`echo $pid_cpu |awk '{print $2}'` cmd=`echo $pid_cpu |awk '{print $3}'` if [ `echo "$cpu > 85" | bc` -eq 1 ];then echo "PID CPU(%) Mem(%) CMD" echo $pid_cpu if [[ $cmd =~ "mine" ]];then rm -rf /var/tmp/.22 fi else echo "cpu is normal." fi
(2)设置定时任务
crontab -e
* * * * * /root/clean_host.sh >/dev/null 2>&1
标签:清理,pid,echo,awk,监控,print,cpu,挖矿 From: https://www.cnblogs.com/yeyuzhuanjia/p/17975022