我正在尝试在cron中创建一个脚本来杀死僵尸进程。我需要它每小时运行一次,并在检测到僵尸时显示日志消息。我创建了一个bash脚本,但收到许多错误,包括意外的文件结尾。
我尝试创建cron作业,但是不确定该过程以及如何设置它。
#!/bin/bash case "$1" in --admin) stat=`ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print"pid: "$3" *** parent_pid: "$4" *** status: "$10" *** process: "$13}' | grep ": Z"` if ((${#stat} > 0));then echo zombie processes found: echo . ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print"pid: "$3" *** parent_pid: "$4" *** status: "$10" *** process: "$13}' | grep ": Z" echo -n "Kill zombies? [y/n]: " read keyb if [ $keyb == 'y' ];then echo killing zombies.. ps ax | awk '{print $1}' | grep -v "PID" | xargs -n 1 ps lOp | grep -v "UID" | awk '{print$4" status:"$10}' | grep "status:Z" | awk '{print $1}' | xargs -n 1 kill -9 fi else echo no zombies found! fi ;;