批量ssh执行命令
[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