Preface :
The company has more than 150 servers, on each server deployed script, and then this script has been running, there are some problems, now to remote batch to kill these processes, tossing for half a day, the following script can be implemented
Script :
#/bin/bash
For i in ' cat/home/zhangdl/old/ip.txt | Grep-i-V Port | awk ' {print $} '
Do
Ssh-p 888 $i "PS aux | Grep-v grep | grep amateurback.sh | awk ' {print \$2} ' | Xargs Kill "
If [$? = = 1];then
echo $i >>/home/zhangdl/old/error.txt
Fi
Done
parsing :
(1) Ip.txt inside the format is as follows, inconvenient words use XXX instead of
XXX base 61.190.XX. XX Xxxjidi xxx,xxx,xxx,xxx,xxx
(2) For security, the SSH port is set to another port, assuming this is 888 port, if it is 22 port, will be "xxx base (Port 22)", the remaining is the other port
(3) After filtering the IP to traverse
Ssh-p 888 "PS aux | Grep-v grep | grep amaterback.sh | awk ' {print \$2} ' Xargs kill '
Select the process number to Xargs kill, SSH combined with awk to use the $ symbol escaped, here no matter how many processes you have, as long as the conditions, will kill off.
This article is from the "Court of the Odd Tree" blog, please be sure to keep this source http://zhangdl.blog.51cto.com/11050780/1792179
Linux script implements bulk SSH remote kill process