Skip to content

Instantly share code, notes, and snippets.

@Ladicle
Last active August 29, 2015 14:10
Show Gist options
  • Save Ladicle/9468ee3ff486b44632fa to your computer and use it in GitHub Desktop.
Save Ladicle/9468ee3ff486b44632fa to your computer and use it in GitHub Desktop.
tmuxで指定hostに一斉接続
#!/bin/bash
function usage() {
echo ""
echo "$(basename ${0}) is a tool to connect to multi servers on same time"
echo ""
echo "Usage:"
echo " $(basename ${0}) [<options>] hostname..."
echo "Options:"
echo " --window, -w [name] set window name"
echo " --script, -s [name] run script after connection"
echo " --version, -v print $(basename ${0}) version"
echo " --help, -h print this command discription"
echo ""
exit 0
}
function version {
echo -e "$(basename ${0}) version 1.0\n"
exit 0
}
function arg_error {
echo -e "ERROR: wrong number of arguments\n"
exit 1
}
CDIR=$(dirname $0)
[ $# -lt 1 ] && arg_error
while [ $# -gt 0 ]; do
case ${1} in
--window|-w)
WNAME=${2}
shift
;;
--script|-s)
SPATH="${CDIR}/${2}"
shift
;;
--version|-v)
version
;;
--help|-h)
usage
;;
*)
break
;;
esac
shift
done
SDATE=$(date +%s)
SNAME="session-${SDATE}"
[ -z ${WNAME} ] && WNAME="multilogin-${SDATE}"
tmux new-window -n ${WNAME}
tmux new-session -d -n ${WNAME} -s ${SNAME}
tmux send-keys "ssh ${1}" C-m
shift
for host in $*; do
tmux split-window
tmux select-layout tiled
tmux send-keys "ssh ${host}" C-m
done
tmux select-pane -t 0
tmux attach-session -t ${SNAME}
tmux set-window-option synchronize-panes on
tmux send-keys 'export PS1="\[\033[35m\](\t)\[\033[m\] \h \[\033[32m\][\w]\[\033[0m\]\n\[\033[1;36m\]\u\[\033[1;33m\]-> \[\033[0m\]"' C-m
tmux send-keys 'clear' C-m
if [ -e ${SPATH} ]; then
source ${SPATH}
fi
@Ladicle
Copy link
Author

Ladicle commented Nov 26, 2014

sshのconfigに書いているhoge*を取得してログ表示↓

multilogin $(cat ~/.ssh/config|grep hoge -e '1d' -e 's/Host //g')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment