隨機殺死程序
阿新 • • 發佈:2018-12-21
#!/bin/bash while [[ true ]]; do echo "這是一個隨機殺死服務程序的小程式!" read -p "enter your hostname:" hostname echo $hostname for host in $hostname do ssh $host " #程序號 pid=$(ps -ef | grep java | grep opt | awk -F" " '{ print $2}');indexSum=0;for i in $pid;do server[indexSum]=$i;((indexSum++));done;echo ${server[@]} echo "準備開始隨機殺死一個服務程序!!!" number=$[RANDOM%${#server[@]}] sleep 20 echo ${server[$number]} > /tmp/123456 if [[ $? -eq 0 ]]; then echo "已經成功殺死程序!!!" #服務名稱 servername = `ps -ef | grep ${server[$number]} | grep opt | awk -F'/home/admin/htdocs' '{ print $2}' | awk -F'/' '{ print $2}'` echo "服務的名稱是:" "$servername" fi done" done done #!/bin/bash while [[ true ]]; do echo "這是一個隨機殺死服務程序的小程式!" read -p "enter your hostname:" hostname echo $hostname for host in $hostname do ssh $host ' ps -ef | grep java | grep opt | awk -F" " '{ print $2}';indexSum=0;for i in $pid;do server[indexSum]=$i;((indexSum++));done;echo ${server[@]};echo "準備開始隨機殺死一個服務程序!!!";number=$[RANDOM%${#server[@]}];echo $number;sleep 1;echo ${server[$number]} >> /tmp/123456;if [[ $? -eq 0 ]]; then echo "已經成功殺死程序";fi;servername=`ps -ef | grep ${server[$number]} | grep opt | awk -F'/home/admin/htdocs' '{ print $2}' | awk -F'/' '{ print $2}'`;echo "服務的名稱是:" "$servername"' done done