Author Topic: Not a bad MOTD script  (Read 11594 times)

0 Members and 1 Guest are viewing this topic.

Offline
***
Not a bad MOTD script
« on: April 02, 2017, 07:13:09 PM »
First of all to install few things needed for the script (mostly needed if you have minimal install):
Code: [Select]
yum -y install bc lm_sensorsThis script was made very long time ago for one of my FreeBSD servers. Now it`s changed a bit with added functions.
Now the script:
Code: [Select]
#!/bin/bash
#Server Status Script
#https://www.born2host.com
#CPU info
cpumodel=`cat /proc/cpuinfo | head -20 | grep "model name"| awk '{print $4, $5, $6, $7, $8, $10 }'`
core0=`sensors -u | head -11 |grep "temp1_input"| awk '{print $2 }' |awk '{printf("%d\n",$1 + 0.5);}'`
core1=`sensors -u | head -20 |grep "temp2_input"| awk '{print $2 }' |awk '{printf("%d\n",$1 + 0.5);}'`
core2=`sensors -u | head -30 |grep "temp3_input"| awk '{print $2 }' |awk '{printf("%d\n",$1 + 0.5);}'`
core3=`sensors -u | head -40 |grep "temp4_input"| awk '{print $2 }' |awk '{printf("%d\n",$1 + 0.5);}'`
Load1=`cat /proc/loadavg | awk {'print $1'}`
Load5=`cat /proc/loadavg | awk {'print $2'}`
Load15=`cat /proc/loadavg | awk {'print $3'}`
#Users info
user=`whoami`
psa=`ps -Afl | wc -l`
psu=`ps U $user h | wc -l`
#System update need
yum=`yum list updates -q | grep -vc "Updated Packages"`
#Uptime
btime=`last -x | grep reboot | tail -n 1 | awk '{print $1, $2, $6, $7, $8}'`
uptime=`cat /proc/uptime | cut -f1 -d.`
upDays=$((uptime/60/60/24))
upHours=$((uptime/60/60%24))
upMins=$((uptime/60%60))
upSecs=$((uptime%60))
#RAM
mfr=`free -m | head -n 2 | tail -n 1 | awk {'print $4'}`
mfc=`free -m | head -n 3 | tail -n 1 | awk {'print $3'}`
mtc=`free -m | head -n 2 | tail -n 1 | awk {'print $2'}`
swap=`free -m | tail -n 1 | awk {'print $3'}`
#Disk
raid=`cat /proc/mdstat |grep Personalities`
disk=`df -h | awk '{ a = $4 } END { print a }'`
echo -e "
                       \e[96mSystem Server Status
   
\e[39m- \e[31mServer Name                  \e[35m= \e[92m`hostname`
\e[39m- \e[31mPublic IP                    \e[35m= \e[92m`dig +short myip.opendns.com @resolver1.opendns.com`
\e[39m- \e[31mOS Version                   \e[35m= \e[92m`cat /etc/redhat-release`
\e[39m- \e[31mPlatform                     \e[35m= \e[92m`uname -orpi`
\e[39m- \e[31mCPU model                    \e[35m= \e[92m$cpumodel
\e[39m- \e[31mCPU Usage                    \e[35m= \e[92m$Load1 (1 min) \e[93m>> \e[92m$Load5 (5 min) \e[93m>> \e[92m$Load15 (15 min)
\e[39m- \e[31mUsers logged                 \e[35m= \e[92mCurrently `users | wc -w` users logged on
\e[39m- \e[31mCurrent user                 \e[35m= \e[92m$user
\e[39m- \e[31mSystem boot                  \e[35m= \e[92m$btime
\e[39m- \e[31mSystem Uptime                \e[35m= \e[92m$upDays days $upHours hours $upMins minutes $upSecs seconds
\e[39m- \e[31mSystem Update                \e[35m= \e[31m$yum \e[92mpackages can be updated
\e[39m- \e[31mTotal Memory(RAM)           \e[35m= \e[92m$mtc Mb
\e[39m- \e[31mMemory free (real)           \e[35m= \e[92m$mfr Mb
\e[39m- \e[31mMemory free (cache)          \e[35m= \e[92m$mfc Mb
\e[39m- \e[31mSwap in use                  \e[35m= \e[92m$swap Mb
\e[39m- \e[31mProcesses                    \e[35m= \e[92mYou are running $psu of $psa processes
\e[39m- \e[31mRAID                         \e[35m= \e[92m$raid
\e[39m- \e[31mDisk Space Used              \e[35m= \e[92m$disk
\e[39m- \e[31mCPU Temperature              \e[35m= \e[92mCore1 $core0 °C ; Core2 $core1 °C ; Core3 $core2 °C ; Core4 $core3 °C ;
\e[39m
" > /etc/motd
#exit 0
The script will put all the information in /etc/motd and it`s a good idea to put that script in your crontab to run every 1 hour for example(if you want every 5min).
After you run the script you can relog to your server or "cat /etc/motd" to see the output. Should be something similar to this:
Code: [Select]
[root@srv1 ~]# cat /etc/motd

                       System Server Status

- Server Name                  = srv1.born2host.com
- Public IP                        = 77.236.172.141
- OS Version                     = CentOS release 6.8 (Final)
- Platform                        = 2.6.32-642.11.1.el6.x86_64 x86_64 x86_64 GNU/Linux
- CPU model                     = Intel(R) Core(TM)2 Duo CPU T8100 2.10GHz
- CPU Usage                     = 0.14 (1 min) >> 0.04 (5 min) >> 0.01 (15 min)
- Users logged                  = Currently 1 users logged on
- Current user                   = root
- System boot                   = reboot system Dec 17 11:29
- System Uptime               = 106 days 8 hours 16 minutes 47 seconds
- System Update               = 0 packages can be updated
- Total Ram                      = 2886 Mb
- Memory free (real)         = 272 Mb
- Memory free (cache)       = 1716 Mb
- Swap in use                   = 264 Mb
- Processes                      = You are running 113 of 140 processes
- RAID                             = Personalities :
- Disk Space Used             = 1%
- CPU Temperature            = Core1 33 °C ; Core2  °C ; Core3  °C ; Core4  °C ;

[root@srv1 ~]#
I hope you like it.
« Last Edit: April 02, 2017, 07:28:35 PM by darkness »
UNIX is a very simple OS, but you have to be a GENIUS to understand it ...