Skip to content

Instantly share code, notes, and snippets.

@imchao9
Created December 1, 2016 06:12
Show Gist options
  • Select an option

  • Save imchao9/856de153268d7143f81b3f202953b0c3 to your computer and use it in GitHub Desktop.

Select an option

Save imchao9/856de153268d7143f81b3f202953b0c3 to your computer and use it in GitHub Desktop.
本地通过ssh执行远程服务器的脚本
#!/bin/bash
#变量定义
ip_array=("192.168.1.1" "192.168.1.2" "192.168.1.3")
user="test1"
remote_cmd="/home/test/1.sh"
#本地通过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 "remote_cmd"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment