#! /bin/bash
10 # unset any variable which system may be using
11
12 # clear the screen
13 clear
14
15 unset tecreset os architecture kernelrelease internalip externalip nameserver loadaverage
16
17 while getopts iv name
18 do
19 case $name in
20 i)iopt=1;;
21 v)vopt=1;;
22 *)echo "Invalid arg";;
23 esac
24 done
25
26 if [[ ! -z $iopt ]]
27 then
28 {
29 wd=$(pwd)
30 basename "$(test -L "$0" && readlink "$0" || echo "$0")" > /tmp/scriptname
31 scriptname=$(echo -e -n $wd/ && cat /tmp/scriptname)
32 su -c "cp $scriptname /usr/bin/monitor" root && echo "Congratulations! Script Installed, now run monitor Command" || echo "Installation failed"
33 }
34 fi
35
36 if [[ ! -z $vopt ]]
37 then
38 {
39 echo -e "tecmint_monitor version 0.1
Designed by Tecmint.com
Released Under Apache 2.0 License"
40 }
41 fi
42
43 if [[ $# -eq 0 ]]
44 then
45 {
46
47
48 # Define Variable tecreset
49 tecreset=$(tput sgr0)
50
51 # Check if connected to Internet or not
52 ping -c 1 google.com &> /dev/null && echo -e 'E[32m'"Internet: $tecreset Connected" || echo -e 'E[32m'"Internet: $tecreset Disconnected"
53
54 # Check OS Type
55 os=$(uname -o)
56 echo -e 'E[32m'"Operating System Type :" $tecreset $os
57
58 # Check OS Release Version and Name
59 cat /etc/os-release | grep 'NAME|VERSION' | grep -v 'VERSION_ID' | grep -v 'PRETTY_NAME' > /tmp/osrelease
60 echo -n -e 'E[32m'"OS Name :" $tecreset && cat /tmp/osrelease | grep -v "VERSION" | cut -f2 -d"
61 echo -n -e 'E[32m'"OS Version :" $tecreset && cat /tmp/osrelease | grep -v "NAME" | cut -f2 -d"
62
63 # Check Architecture
64 architecture=$(uname -m)
65 echo -e 'E[32m'"Architecture :" $tecreset $architecture
66
67 # Check Kernel Release
68 kernelrelease=$(uname -r)
69 echo -e 'E[32m'"Kernel Release :" $tecreset $kernelrelease
70
71 # Check hostname
72 echo -e 'E[32m'"Hostname :" $tecreset $HOSTNAME
73
74 # Check Internal IP
75 internalip=$(hostname -I)
76 echo -e 'E[32m'"Internal IP :" $tecreset $internalip
77
78 # Check External IP
79 externalip=$(curl -s ipecho.net/plain;echo)
80 echo -e 'E[32m'"External IP : $tecreset "$externalip
81
82 # Check DNS
83 nameservers=$(cat /etc/resolv.conf | sed '1 d' | awk '{print $2}')
84 echo -e 'E[32m'"Name Servers :" $tecreset $nameservers
85
86 # Check Logged In Users
87 who>/tmp/who
88 echo -e 'E[32m'"Logged In users :" $tecreset && cat /tmp/who
89
90 # Check RAM and SWAP Usages
91 free -h | grep -v + > /tmp/ramcache
92 echo -e 'E[32m'"Ram Usages :" $tecreset
93 cat /tmp/ramcache | grep -v "Swap"
94 echo -e 'E[32m'"Swap Usages :" $tecreset
95 cat /tmp/ramcache | grep -v "Mem"
96
97 # Check Disk Usages
98 df -h| grep 'Filesystem|/dev/sda*' > /tmp/diskusage
99 echo -e 'E[32m'"Disk Usages :" $tecreset
100 cat /tmp/diskusage
101
102 # Check Load Average
103 loadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $10 $11 $12}')
104 echo -e 'E[32m'"Load Average :" $tecreset $loadaverage
105
106 # Check System Uptime
107 tecuptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)
108 echo -e 'E[32m'"System Uptime Days/(HH:MM) :" $tecreset $tecuptime
109
110 # Unset Variables
111 unset tecreset os architecture kernelrelease internalip externalip nameserver loadaverage
112
113 # Remove Temporary Files
114 rm /tmp/osrelease /tmp/who /tmp/ramcache /tmp/diskusage
115 }
116 fi
117 shift $(($OPTIND -1))