-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathssh_utils.sh
More file actions
93 lines (72 loc) · 2.05 KB
/
ssh_utils.sh
File metadata and controls
93 lines (72 loc) · 2.05 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
# copy this into your ~/.bashrc or ~/.profile or ~/.bashprofile
start-remote-notebook() {
# do things with parameters like $1 such as
# assumes remote port is 9999 and local is 8080
SERVER=$1
PORT=${2-8080}
ssh -fNL $PORT:localhost:9999 $SERVER
}
kill-remote-notebook(){
SERVER=$1
ps -ef | grep "9999 $SERVER" | grep -v grep | awk '{print $2}' | xargs kill -9
}
# Tensorboard tools
start-remote-tensorboard() {
# do things with parameters like $1 such as
# assumes remote port is 9999 and local is 8080
SERVER=$1
PORT=${2-7007}
ssh -fNL $PORT:localhost:6006 $SERVER
}
kill-remote-tensorboard(){
SERVER=$1
ps -ef | grep "7007 $SERVER" | grep -v grep | awk '{print $2}' | xargs kill -9
}
# Remote developing tools
mount-remote() {
SERVER=$1
if [ ! -d /mnt/"$SERVER" ]; then
sudo mkdir /mnt/"$SERVER"
sudo chown "$USER" /mnt/"$SERVER"
fi
sshfs "$SERVER": /mnt/"$SERVER"
}
umount-remote() {
SERVER=$1
# kill bash tunnel
#ps -ef | grep "22 $SERVER" | grep -v grep | awk '{print $2}' | xargs kill -9
# umount
sudo umount /mnt/"$SERVER"
}
# autocompletion support for ubuntu
_myssh() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=$(grep '^Host' ~/.ssh/config | grep -v '[?*]' | cut -d ' ' -f 2-)
COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
return 0
}
_mysshsync() {
local cur prev opts
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
diropts=$( ls "/home/edison/PycharmProjects/")
diropts+=" data"
if [ $prev == "sync-project" ]; then
COMPREPLY=( $(compgen -W "$diropts" -- ${cur}) )
return 0
else
_myssh
return 0
fi
}
complete -F _myssh start-remote-notebook
complete -F _myssh kill-remote-notebook
complete -F _myssh start-remote-tensorboard
complete -F _myssh kill-remote-tensorboard
complete -F _myssh mount-remote
complete -F _myssh umount-remote
complete -F _mysshsync sync-project