-
Notifications
You must be signed in to change notification settings - Fork 1
/
monitor.sh
199 lines (165 loc) · 6.48 KB
/
monitor.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
#########################################################
### https://github.com/flover97/monitor ###
#########################################################
#========================================================
#Variables
#========================================================
script=/usr/bin/monitor
tdir=$(mktemp -d /tmp/monitor.XXXXXXXXX)
#========================================================
#================[Clear old versions]====================
#========================================================
if [ -e "$script" ]; then
</etc/passwd grep /bash | cut -d: -f6 >> "$tdir/home-rm.tmp"
while read -r home
do
find "$home" -iname ".*hrc" >> "$tdir/hrc-rm.tmp"
find "$home" -iname ".*profile" >> "$tdir/profile-rm.tmp"
done <"$tdir/home-rm.tmp"
while read -r hrc
do
sed -i 's@alias monitor="sh /usr/bin/monitor"@@' "$hrc"
done <"$tdir/hrc-rm.tmp"
while read -r profile
do
sed -i 's@/usr/bin/monitor@@' "$profile"
done <"$tdir/profile-rm.tmp"
rm -rf /tmp/monitor.*/*
fi
#========================================================
#=====================[Installation]=====================
#========================================================
</etc/passwd grep /bash | cut -d: -f6 >> "$tdir/home.tmp"
shell=$SHELL
case $shell in
/bin/bash | /usr/bin/bash)
while read -r home
do
find "$home" -iname ".bashrc" >> "$tdir/hrc.tmp"
find "$home" -iname ".*profile" >> "$tdir/profile.tmp"
done <"$tdir/home.tmp"
;;
/bin/sh | /usr/bin/sh)
while read -r home
do
find "$home" -iname ".*shrc" >> "$tdir/hrc.tmp"
find "$home" -iname ".*profile" >> "$tdir/profile.tmp"
done <"$tdir/home.tmp"
;;
/bin/zsh | /usr/bin/zsh)
while read -r home
do
find "$home" -iname ".*zshrc" >> "$tdir/hrc.tmp"
find "$home" -iname ".*profile" >> "$tdir/profile.tmp"
done <"$tdir/home.tmp"
;;
/bin/csh | /usr/bin/csh)
while read -r home
do
find "$home" -iname ".*cshrc" >> "$tdir/hrc.tmp"
find "$home" -iname ".*profile" >> "$tdir/profile.tmp"
done <"$tdir/home.tmp"
;;
/bin/ksh | /usr/bin/ksh)
while read -r home
do
find "$home" -iname ".*kshrc" >> "$tdir/hrc.tmp"
find "$home" -iname ".*profile" >> "$tdir/profile.tmp"
done <"$tdir/home.tmp"
;;
/bin/tcsh | /usr/bin/tcsh)
while read -r home
do
find "$home" -iname ".*tcshrc" >> "$tdir/hrc.tmp"
find "$home" -iname ".*profile" >> "$tdir/profile.tmp"
done <"$tdir/home.tmp"
;;
esac
while read -r hrc
do
echo 'alias monitor="sh /usr/bin/monitor"' >>"$hrc"
done <"$tdir/hrc.tmp"
while read -r profile
do
echo '/usr/bin/monitor' >>"$profile"
done <"$tdir/profile.tmp"
#============================================================
cat << "EOF" > $script
#########################################################
### https://github.com/flover97/monitor ###
#########################################################
#===================[Script body]========================
#!/bin/bash
script=/usr/bin/monitor
tdir=$(mktemp -d /tmp/monitor.XXXXXXXXX)
echo "==============================================================================="
if ! wget -q --spider http://google.com
then
echo "Internet: Disconnected"
else
echo "Internet: Connected"
fi
# Check OS Release Version and Name
echo "==============================================================================="
name=$(</etc/os-release grep 'PRETTY_NAME=' | cut -f2 -d\")
echo "OS :" "$name"
# Check Architecture
echo "==============================================================================="
architecture=$(uname -m)
echo "Architecture :" "$architecture"
# Check Kernel Release
echo "==============================================================================="
kernelrelease=$(uname -r)
echo "Kernel Release :" "$kernelrelease"
# Check Hostname
echo "==============================================================================="
hostname=$(hostname)
echo "Hostname :" "$hostname"
# Check Internal IP
echo "==============================================================================="
internalip=$(hostname -I)
echo "Internal IP :" "$internalip"
# Check External IP
echo "==============================================================================="
externalip=$(curl -s ipecho.net/plain;echo)
echo "External IP :" "$externalip"
# Check DNS
echo "==============================================================================="
nameservers=$(</etc/resolv.conf grep "nameserver" | awk '{print $2}')
echo "Name Servers :"
echo "$nameservers"
# Check Logged In Users
echo "==============================================================================="
echo "Logged In users :"
who
# Check RAM and SWAP Usages
echo "==============================================================================="
echo "Memory usage :"
free -h
# Check Disk Usage
echo "==============================================================================="
df -h| grep 'Filesystem\|/dev/sda*\|/dev/mapper*\|/dev/md*\|/dev/disk*\|/dev/vda*\|/dev/dm*' >> "$tdir/diskusage.tmp"
echo "Disk Usage :"
cat "$tdir/diskusage.tmp"
# Check Load Average
echo "==============================================================================="
loadaverage=$(</proc/loadavg awk '{print $1,$2,$3}')
echo "Load Average :" "$loadaverage"
# Check iowait
echo "==============================================================================="
iowait=$(iostat -c|awk '/^ /{print $4}')
echo "I/O in %:" "$iowait"
# Check System Uptime
echo "==============================================================================="
uptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)
echo "System Uptime Days/(HH:MM) :" "$uptime"
echo "==============================================================================="
EOF
chmod +x $script
rm -rf /tmp/monitor.*
echo "==============================================================================="
echo "Job Done つ◕◡◕つ"
echo Instalation directory: $script
echo "To call script enter: monitor"
echo "==============================================================================="