Created
April 20, 2013 23:07
-
-
Save danielkza/5427767 to your computer and use it in GitHub Desktop.
This file contains 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 | |
SSH=$(which ssh) | |
hosts=() | |
params=() | |
sep_found=0 | |
for arg in "$@" | |
do | |
if [ $sep_found -eq 0 ] && [ "$arg" = "--" ]; then | |
params=("${hosts[@]}") | |
hosts=() | |
sep_found=1 | |
continue | |
fi | |
hosts=("${hosts[@]}" "$arg") | |
done | |
if [ ${#hosts[@]} -eq 0 ]; then | |
echo "Usage: sshhop [ssh_param1 [ssh_param2 ... ssh_paramN] --] host1 host2 [... hostN]" | |
exit 1 | |
fi | |
last_host_index=$(( ${#hosts[@]} - 1 )) | |
last_host=${hosts[$last_host_index]} | |
unset hosts[$last_host_index] | |
command= | |
if [ ${#params[@]} -eq 0 ]; then | |
params_str= | |
else | |
params_str=$(printf "%q " "${params[@]}") | |
fi | |
for host in "${hosts[@]}" | |
do | |
command="${command} ssh -A -t ${params_str} ${host}" | |
done | |
command="${command} ssh -A ${params_str} ${last_host}" | |
echo "$command" | |
$command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment