-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh_help.bak
65 lines (59 loc) · 1.29 KB
/
ssh_help.bak
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# set -x
unset='-'
server=${1}
shift
command=${@}
########## FUNCTIONS
function log() {
msg=${@}
timestamp=$(date '+%F %T')
if [[ -n ${debug} ]]
then
printf "%18s |%s| %s\n" "${timestamp}" "${version}" "${msg}" | tee -a ${logfile}
else
printf "%18s |%s| %s\n" "${timestamp}" "${version}" "${msg}" >> ${logfile}
fi
}
function pick() {
printf "Not implemented yet"
}
function set_tmux() {
if [[ -n ${TMUX} ]]
then
title="${1}"
session=${TMUX/,*}
tmux -S ${session} rename-window "${title}"
fi
}
function run_ssh_command() {
check_sock
ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o ConnectTimeout=10 ${server} "${command[@]}"
}
function run_ssh() {
check_sock
set_tmux ${server/.dap*}
ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o ConnectTimeout=10 ${server}
ssh_result=$?
set_tmux ${unset}
}
function check_sock() {
csock=$(find /tmp -name 'agent*' 2> /dev/null)
if [[ -z ${SSH_AUTH_SOCK} ]] || [[ ${csock} != ${SSH_AUTH_SOCK} ]]
then
printf "Renewing SOCK %s\n" "${csock}"
export SSH_AUTH_SOCK=${csock}
fi
}
if [[ -n ${server} ]]
then
if [[ -z ${command} ]]
then
run_ssh
else
run_ssh_command
fi
else
pick
fi
# set +x