Linux script implements bulk SSH remote kill process

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.