-
-
Save imchao9/856de153268d7143f81b3f202953b0c3 to your computer and use it in GitHub Desktop.
本地通过ssh执行远程服务器的脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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