-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh-mini-tool.sh
executable file
·90 lines (71 loc) · 1.82 KB
/
ssh-mini-tool.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
#!/bin/bash
export LBLUE="\e[1;34m"
export LGREEN="\e[1;32m"
export RED="\e[0;31m"
export Z="\e[0m"
clear
echo -e "$LBLUE\bWelcome to the mini-remote tool. This is a tool for use ssh or ssh packages. Please complete the questions below: $Z"
echo -n "Server username: "
read VAR1
echo -n "Server name/ip: "
read VAR2
echo -n "Action [shutdown/reboot/alert/shell]: "
read VAR3
if [[ $VAR3 = shutdown ]]
then
clear
echo -e "$LBLUE\bSSH shutdown tool $Z"
ssh -t -oStrictHostKeyChecking=no $VAR1@$VAR2 "
sudo shutdown -h now
"
echo -e "$LGREEN\bThe computer was shut down successfully $Z"
exit 0
elif [[ $VAR3 = reboot ]]
then
clear
echo -e "$LBLUE\bSSH reboot tool $Z"
ssh -t -oStrictHostKeyChecking=no $VAR1@$VAR2 "
sudo reboot
"
echo -e "$LGREEN\bThe computer was rebooted successfully $Z"
exit 0
elif [[ $VAR3 = alert ]]
then
clear
echo -e "$LBLUE\bSSH notification tool $Z"
echo -n "Type of alert [none/low/normal/critical]: "
read VAR4
echo -n "Notification text: "
read VAR5
if [[ $VAR4 = low ]] || [[ $VAR4 = normal ]] || [[ $VAR4 = critical ]]
then
var3=$(ssh -t -oStrictHostKeyChecking=no $VAR1@$VAR2 "
notify-send --urgency=$VAR4 $VAR5
")
if [[ $? = 0 ]]
then
echo -e "$LGREEN\bNotification was sent successfully $Z"
exit 0
else
echo -e "$RED\bAn error has occurred"
exit 1
fi
elif [[ $VAR4 = none ]]
then
ssh -t -oStrictHostKeyChecking=no $VAR1@$VAR2 "
notify-send $VAR5
"
exit 0
else
echo -e "$RED Unknown command '$VAR4' $Z"
exit 1
fi
elif [[ $VAR3 = shell ]]
then
echo -e "$LBLUE\bSSH shell $Z"
ssh -t -oStrictHostKeyChecking=no $VAR1@$VAR2
exit 0
else
echo -e "$RED\bUnknown command '$VAR3' $Z"
exit 1
fi