Last active
December 19, 2015 10:49
-
-
Save dekokun/5943366 to your computer and use it in GitHub Desktop.
VagrantでMultiVMの時にsshのconfigの結果をキャッシュしたりするやつ AWSとvagrantを組み合わせていてvagrant sshが遅いが、vagrant ssh-config hoge --host hoge >> ~/.ssh/config をしてconfigの設定がどんどん増えていくのも嫌という人はどうぞ
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 | |
while getopts rh:d OPT | |
do | |
case $OPT in | |
"r" ) FLG_R="TRUE" ;; | |
"h" ) FLG_H="TRUE" ; host="$OPTARG" ;; | |
"d" ) FLG_D="TRUE" ;; | |
esac | |
done | |
debug_log() { | |
if [ "$FLG_D" == "TRUE" ]; then | |
echo $@ | |
fi | |
} | |
usage() { | |
echo usage: | |
echo $0 -h name [-r] | |
echo r option: refresh ssh_config | |
} | |
if [ "$FLG_H" != "TRUE" ]; then | |
echo "-hは必須" | |
usage | |
exit 1 | |
fi | |
debug_log debug mode | |
sshconfig=./ssh_${host}.conf | |
debug_log config: $sshconfig | |
if [ -d $sshconfig ];then | |
echo ${sshconfig}はファイルでおk | |
exit | |
elif [ "$FLG_R" == "TRUE" -o ! -f $sshconfig ];then | |
command="vagrant ssh-config $host --host $host" | |
debug_log command: $command | |
$command > $sshconfig | |
fi | |
command="ssh -F $sshconfig $host" | |
debug_log command: $command | |
$command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment