-
Notifications
You must be signed in to change notification settings - Fork 5
/
cysh
executable file
·42 lines (35 loc) · 859 Bytes
/
cysh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# set -x
#function lookup_host() {
# if [[ $1 =~ ^([^.]*|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
# echo "$1"
# else
# host -t a "${1}" | sed -e $'/.* has address / { s///; p; d; q; }; /.*\tA\t/ { s///; p; d; q; }; d;' | head -n 1
# fi
#}
machine=$1
shift 1
#user=${machine%@*}
#addr=$(lookup_host "${machine#*@}")
if [[ $1 == "-l" ]]; then
ssh "$machine" "tmux list-sessions"
exit 0
fi
if [[ $1 =~ \^.* ]]; then
session=${1#^}
shift 1
else
session=$(date -u +"%Y%m%d%H%M%S")
fi
while true; do
ssh "$@" -t -e none \
-o ConnectTimeout=2 \
-o ServerAliveCountMax=4 \
-o ServerAliveInterval=2 \
-o TCPKeepAlive=no \
"$machine" bash -i -l -c "\"tmux -u -CC new-session -A -s $session\""
case "$?" in
(0) break;;
(*) sleep 1;;
esac
done