您的位置:首页 > 其它

批量ssh执行命令

2016-01-15 14:23 405 查看
[root@openfire1 script]# cat test.sh
#!/bin/bash

#本地通过ssh执行远程服务器的脚本
for ip in `cat iplist`
do
echo $1
if [[ -z $1 ]]; then #"-z",如果为空
echo "Not find command."
break
else
echo "$ip----------------------"
ssh $ip $1
fi
done

-------------------------------------------------------------------------

-------------------------------------------------------------------------

[root@openfire1 script]# cat test.sh

#!/bin/bash

#变量定义

ip_array=("172.16.100.23" "172.16.100.24" "172.16.100.25" "172.16.100.26" "172.16.100.27")

user="root"

remote_cmd=date

#本地通过ssh执行远程服务器的命令

for ip in ${ip_array[*]}

do

if [ $ip = "192.168.1.1" ]; then

port="7777"

else

port="22"

fi

ssh -t -p $port $user@$ip $1

echo done!

done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: