-
Notifications
You must be signed in to change notification settings - Fork 2
/
sshscreen.sh
182 lines (164 loc) · 3.31 KB
/
sshscreen.sh
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
SCREENDIR="$HOME/.sshscreen"
source /etc/profile
if [ ! -d "$SCREENDIR" ]; then
mkdir -p $SCREENDIR
chmod 700 $SCREENDIR
fi
listScreens() {
SCREENDIR=$SCREENDIR screen -list
}
createScreen() {
if [ -z $1 ]
then
echo "Please write Session name"
return
fi
if SCREENDIR=$SCREENDIR screen -ls | grep -o "[0-9]*\.$1" >/dev/null 2>&1 ;
then
echo "Session name \"$1\" is already used"
return
fi
SCREENDIR=$SCREENDIR screen -e^Bb -S $1
}
closeScreen() {
if [ -z $1 ]
then
echo "Please write Session name"
return
fi
SCREENDIR=$SCREENDIR screen -X -S $1 quit
}
reatachScreen(){
if [ -z $1 ]
then
echo "Please write Session name"
return
fi
SCREENDIR=$SCREENDIR screen -e^Bb -rd $1
}
mirrorScreen(){
if [ -z $1 ]
then
echo "Please write Session name"
return
fi
SCREENDIR=$SCREENDIR screen -e^Bb -x $1
}
deattachScreen() {
if [ -z $1 ]
then
echo "Please write Session name"
return
fi
SCREENDIR=$SCREENDIR screen -d $1
}
helpFunc="
Here is avaible commands
(li)st
List all screens for $USER
(cr)eate Screen-Name
Create New screen
(cl)ose Screen-Name
Close Screen
(re)atach Screen-Name
Reattach to screen
(mi)rror Screen-Name
Attach screen second or third times for multiple usage
(de)atach Screen-Name
Deatach Screen
(ex)it
Close this connection
"
helpFunc() {
if [ -z "$funcoutput" ];
then
echo -e "$helpFunc"
else
echo -e "$helpFunc"
echo -e "$funcoutput"
fi
}
countdown() {
trap exit INT EXIT
tput sc
for i in {30..0}
do
if ! kill -0 $1 > /dev/null 2>&1; then
exit
fi
tput sc
tput cup 3 5; echo "Time left $i "
tput rc
if [ $i = "0" ]; then
clear
echo "No command is given."
echo "Quiting ...."
kill -9 $1 >/dev/null 2>&1
exit
fi
sleep 1
done
}
while true
do
tput clear
tput cup 2 5
tput setaf 6
countdown $$ &
countdown_pid=$!
echo -e "SSH Screen Select:\tWelcome to Server $HOSTNAME"
tput sgr0
helpFunc
echo
if [ -z "$1" ]
then
read -e -p 'What do you want ? »' noargstart
tput rc
noargstartarray=($(echo $noargstart | tr " " "\n"))
set ${noargstartarray[@]}
else
exitonexit="yes"
fi
kill $countdown_pid >/dev/null 2>&1
wait $countdown_pid 2>/dev/null
case $1 in
list|li)
shift 1
funcoutput=`listScreens`
;;
create|cr)
shift 1
funcoutput=`createScreen $@`
;;
close|cl)
shift 1
funcoutput=`closeScreen $@`
;;
reatach|re)
shift 1
funcoutput=`reatachScreen $@`
;;
mirror|mi)
shift 1
funcoutput=`mirrorScreen $@`
;;
deattach|de)
shift 1
funcoutput=`deattachScreen $@`
;;
exit|ex)
clear
exit
;;
*)
funcoutput="ERR. Command not found"
;;
esac
if [ ! -z "$exitonexit" ]
then
echo -e "$funcoutput"
break
fi
set --
done