-
-
Save imchao9/34cf0eea4a5042eb695169a301e468d2 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