-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20-sysinfo
65 lines (49 loc) · 1.54 KB
/
20-sysinfo
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
#!/bin/bash
function sec2time (){
local input=$1
if [ $input -lt 60 ]; then
echo "$input seconds"
else
((days=input/86400))
((input=input%86400))
((hours=input/3600))
((input=input%3600))
((mins=input/60))
local daysPlural="s"
local hoursPlural="s"
local minsPlural="s"
if [ $days -eq 1 ]; then
daysPlural=""
fi
if [ $hours -eq 1 ]; then
hoursPlural=""
fi
if [ $mins -eq 1 ]; then
minsPlural=""
fi
echo "$days day$daysPlural, $hours hour$hoursPlural, $mins minute$minsPlural"
fi
}
user=$(whoami)
# ip=`ifconfig $(route | grep default | awk '{ print $8 }') | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'`
lastlog=`lastlog -u ${user} | grep -v Latest | awk '{ printf $6" "$5" "$9" at "$7" from "$3 }'`
distro=`cat /etc/*release | grep "PRETTY_NAME" | cut -d "=" -f 2- | sed 's/"//g'`
kernel=`uname -sr`
updates=`apt-get -q -y --ignore-hold --allow-change-held-packages --allow-unauthenticated -s dist-upgrade | /bin/grep ^Inst | wc -l`
hostinfo=`hostname -i`
# uptime=`uptime | grep -ohe 'up .*' | sed 's/,/\ hours/g' | awk '{ printf $2" "$3 }'`
uptime="$(sec2time $(cut -d "." -f 1 /proc/uptime))"
uptime="$uptime ($(date -d "@"$(grep btime /proc/stat | cut -d " " -f 2) +"%d-%m-%Y %H:%M:%S"))"
W="\e[0;39m"
G="\e[1;32m"
echo -e "
Distro $distro
Kernel $kernel
Hostname $hostinfo
Last Login $lastlog
Uptime $uptime
Updates $G$updates$W
"
if [ -f /var/run/reboot-required ]; then
echo "*** System restart required ***"
fi