查询net-tools软件包有没有安装,没有则安装
if rpm -q net-tools &>/dev/null; then echo "sysstat is already installed." else echo "sysstat is not installed!" yum -y install net-tools fi
检测文件是否存在并读取文件中的数值
echo "检查病毒进程是否存在" if [ -f /tmp/.X11-unix/11 ] then echo "The file 11 exist" var=`cat /tmp/.X11-unix/11` echo “pid1 is ” $var kill -9 $var echo $var "病毒进程1已被杀死" else echo "病毒进程1不存在" fi
查询进程并杀之
ps -ef | grep tracepath | grep -v grep | awk '{print $2}'| sed -e "s/^/kill -9 /g" | sh echo "删除tracepath进程"
netstat -anp|grep 119.205.235.58 |awk '{printf $7}'|cut -d/ -f1| sed -e "s/^/kill -9 /g" | sh echo "杀挖矿进程"
检查有没有添加定时任务,没有则删除原有的某条定时任务并添加,重载crond服务。
echo "添加定时任务" if [ `grep -c "shadu.sh" /var/spool/cron/root` -ne '0' ] then echo "已存在定时任务" sed -i '/systemd-private/d' /var/spool/cron/root else echo "定时任务不存在添加定时任务" echo '*/1 * * * * /home/shadu.sh' >> /var/spool/cron/root sleep 1 service crond reload echo "重启定时任务服务"
fi
原创文章,作者:bd101bd101,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/270998.html