Skip to content

Instantly share code, notes, and snippets.

@dekokun
Last active December 19, 2015 10:49
Show Gist options
  • Save dekokun/5943366 to your computer and use it in GitHub Desktop.
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の設定がどんどん増えていくのも嫌という人はどうぞ
#!/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