天天看点

ssh非交互式远程命令

注:博文为转载博文,原文说明如下;

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://seneagle.blog.51cto.com/1319845/1676582        

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

#!bin/bash

Passwd=123456

#定义数组,存储ip地址

declare

-a IPAddress

IPAddress=(

"10.0.60.102"

"10.0.60.103"

"10.0.60.202"

"10.0.60.203"

"10.0.60.215"

)

numsucess=0

numfail=0

#循环遍历数组

for

IP 

in

${IPAddress[@]}

do

sshpass -p $Passwd 

ssh

-o StrictHostKeyChecking=no $IP  

/etc/init

.d

/ProcessCenter-Process

$1 &> 

/dev/null

if

[ $? -

eq

0 ];

then

echo

"host:$IP sucessed."

let

numsucess=$numsucess+1

else

echo

"host:$IP failed."

let

numfail=$numfail+1

fi

done

echo

-e 

"\033[31m sucess host:$numsucess.\033[0m"

echo

-e 

"\033[31m failed host:$numfail. \033[0m"