-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path_ssh
More file actions
68 lines (51 loc) · 1.45 KB
/
Copy path_ssh
File metadata and controls
68 lines (51 loc) · 1.45 KB
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
66
67
#!/bin/bash
#/ NAME
#/ _ssh -- ssh library for controlmaster, jails
#/
#/ SYNOPSIS
#/ require ssh
function ssh_start {
local hst_remote="$1"; shift
local id_session="$1"; shift
local pth_control="$HOME/.ssh/master-%r@%h:%p-$id_session"
ssh -n -o ControlPath=$pth_control -o ControlMaster=auto -N -f $hst_remote
ssh -n -o ControlPath=$pth_control -O check $hst_remote
}
function ssh_stop {
local hst_remote="$1"; shift
local id_session="$1"; shift
local pth_control="$HOME/.ssh/master-%r@%h:%p-$id_session"
ssh -n -o ControlPath=$pth_control -O exit $hst_remote
}
function ssh_run {
local hst_remote="$1"; shift
local id_session="$1"; shift
local pth_control="$HOME/.ssh/master-%r@%h:%p-$id_session"
ssh -o ControlPath=$pth_control $hst_remote "$@"
}
function ssh_session {
local id_session="$(random_str)"
local pth_control="$HOME/.ssh/master-%r@%h:%p-$id_session"
local hst_remote
for hst_remote in "$@"; do
ssh_start "$hst_remote" "$id_session" &
done | cat &
local cmd_ssh="$(which ssh)"
local tmp_ssh="$(mktemp -d -t XXXXXXXXX)"
mkdir "$tmp_ssh/bin"
local dollar='$'
cat > "$tmp_ssh/bin/ssh" <<EOF
#!/bin/bash
exec $cmd_ssh -o ControlPath=$pth_control "${dollar}@"
EOF
chmod 755 $tmp_ssh/bin/ssh
export PATH_OVERRIDE="$tmp_ssh/bin"
export SHLVL_NAME="ssh"
bash
unset SHLVL_NAME
rm -rf $tmp_ssh
for hst_remote in "$@"; do
ssh_stop "$hst_remote" "$id_session" || true &
done | cat
wait
}