-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
update_motd.sh
78 lines (69 loc) · 2.95 KB
/
update_motd.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
#!/bin/bash
#Script to update motd with relevant information.
#Define output file
motd="/etc/motd"
# Collect information
HOSTNAME=`uname -n`
KERNEL=`uname -r`
CPU=`awk -F '[ :][ :]+' '/^model name/ { print $2; exit; }' /proc/cpuinfo`
ARCH=`uname -m`
PACMAN=`checkupdates | wc -l`
DETECTDISK=`mount -v | fgrep 'on / ' | sed -n 's_^\(/dev/[^ ]*\) .*$_\1_p'`
DISC=`df -h | grep $DETECTDISK | awk '{print $5 }'`
MEMORY1=`free -t -m | grep "Mem" | awk '{print $6" MB";}'`
MEMORY2=`free -t -m | grep "Mem" | awk '{print $2" MB";}'`
MEMPERCENT=`free | awk '/Mem/{printf("%.2f% (Used) "), $3/$2*100}'`
#Time of day
HOUR=$(date +"%H")
if [ $HOUR -lt 12 -a $HOUR -ge 0 ]
then TIME="Morning"
elif [ $HOUR -lt 17 -a $HOUR -ge 12 ]
then TIME="Afternoon"
else TIME="Evening"
fi
#System uptime
uptime=`cat /proc/uptime | cut -f1 -d.`
upDays=$((uptime/60/60/24))
upHours=$((uptime/60/60%24))
upMins=$((uptime/60%60))
upSecs=$((uptime%60))
#System load
LOAD1=`cat /proc/loadavg | awk {'print $1'}`
LOAD5=`cat /proc/loadavg | awk {'print $2'}`
LOAD15=`cat /proc/loadavg | awk {'print $3'}`
#Color variables
#W="\033[00;37m"
W="\033[0m"
B="\033[01;36m"
R="\033[01;31m"
G="\033[01;32m"
N="\033[0m"
#Clear screen before motd
cat /dev/null > $motd
echo -e "
$B. $W
$B/#\ $W _ $B _ _
$B/###\ $W __ _ _ __ ___| |__ $B| (_)_ __ _ ___ __
$B/#####\ $W / _' | '__/ __| '_ \ $B| | | '_ \| | | \ \/ /
$B/##.-.##\ $W | (_| | | | (__| | | |$B| | | | | | |_| |> <
$B/##( )##\ $W \__,_|_| \___|_| |_|$B|_|_|_| |_|\__._/_/\_\\
$B/#.-- --.#\ $W
$B/' '\
" > $motd
echo -e "$G---------------------------------------------------------------" >> $motd
echo -e "$W Good $TIME$A You're Logged Into $B$A$HOSTNAME$W! " >> $motd
echo -e "$G---------------------------------------------------------------" >> $motd
echo -e "$B KERNEL $G:$W $KERNEL $ARCH " >> $motd
echo -e "$B CPU $G:$W $CPU " >> $motd
echo -e "$B MEMORY $G:$W $MEMORY1 / $MEMORY2 - $MEMPERCENT " >> $motd
echo -e "$B USE DISK $G:$W $DISC (Used) " >> $motd
echo -e "$G---------------------------------------------------------------" >> $motd
echo -e "$B LOAD AVG $G:$W $LOAD1, $LOAD5, $LOAD15 " >> $motd
echo -e "$B UPTIME $G:$W $upDays days $upHours hours $upMins minutes $upSecs seconds " >> $motd
#echo -e "$B PROCESSES $G:$W You are running $PSU of $PSA processes " >> $motd
echo -e "$B PACMAN $G:$W $PACMAN packages can be updated " >> $motd
echo -e "$B USERS $G:$W `users | wc -w` users logged in " >> $motd
echo -e "$G---------------------------------------------------------------" >> $motd
echo -e " $W Please do not share your login and use$G sudo$W for$R root$W access " >> $motd
echo -e "$G---------------------------------------------------------------" >> $motd
echo -e "$N" >> $motd