[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  

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2022-02-20
  • 2021-11-03
  • 2021-07-31
猜你喜欢
  • 2021-09-27
  • 2022-01-19
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2021-10-31
相关资源
相似解决方案