Skip to content

Commit 2a6f7fa

Browse files
authored
Create sysinfo.sh
1 parent 050c413 commit 2a6f7fa

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

scripts/sysinfo.sh

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/sh
2+
#
3+
# sysinfo script by Ingar
4+
# https://github.com/IngarKCT/sysinfo
5+
#
6+
7+
#--- [ OS ] ---------------------------
8+
host=`uname -n`
9+
os=`uname -sr`
10+
uptime=`uptime | sed -e 's/[ ][ ]*/ /g;s/ [0-9:]* up \(.*\), [0-9]* user.*/\1/'`
11+
12+
#--- [ MEMORY ] -----------------------
13+
mem_total=`cat /proc/meminfo | grep -i MemTotal | awk '{printf "%d",$2/1024;}'`
14+
mem_free=`cat /proc/meminfo | grep -i MemAvailable | awk '{printf "%d",$2/1024;}'`
15+
mem_used=`echo ${mem_total} ${mem_free} | awk '{printf "%d",$1-$2;}'`
16+
17+
swap_total=`cat /proc/meminfo | grep -i SwapTotal | awk '{printf "%d",$2/1024;}'`
18+
swap_free=`cat /proc/meminfo | grep -i SwapFree | awk '{printf "%d",$2/1024;}'`
19+
swap_used=`echo ${swap_total} ${swap_free} | awk '{printf "%d",$1-$2;}'`
20+
21+
#--- [ CPU ] --------------------------
22+
cpu=`cat /proc/cpuinfo | grep "model name" | head -n 1 | sed 's/[ ][ ]*/ /g;s/^.*: //' | sed -e 's/ @ .*//' | sed -e 's/ [A-Za-z]*[ -]Core Processor//' | sed -e 's/([Tt][Mm])//;s/([Rr])//'`
23+
if [ -z "${cpu}" ]; then
24+
# fallback
25+
cpu=`uname -p`
26+
fi
27+
cpu_speed=`cat /proc/cpuinfo | grep '^cpu MHz' | head -n 1 | cut -f2 -d':' | cut -c2- | cut -f1 -d'.'`
28+
cpu_load=` cat /proc/loadavg | cut -d " " -f 1 | sed 's/,//'`
29+
30+
cpu_count=`grep '^processor' /proc/cpuinfo | wc -l`
31+
if [ "${cpu_count}" -gt 1 ]
32+
then
33+
cpu_count_notice=" * ${cpu_count} cores"
34+
fi
35+
36+
# Detect frequency scaler
37+
if [ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ]; then
38+
cpu_speed_max=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq | awk '{ printf "%d", $1/1000;}'`
39+
cpu_speed_current=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq | awk '{ printf "%d", $1/1000;}'`
40+
cpu_speed="${cpu_speed_current}/${cpu_speed_max}"
41+
fi
42+
43+
#---[ HD ] ----------------------------
44+
sua=`grep 'nodev' '/proc/filesystems' | sed -e 's/nodev\t/-x /' | xargs df --local --total | tail -n 1`
45+
disk_size=`echo $sua | awk '{printf "%d",$2/1048576;}'`;
46+
disk_used=`echo $sua | awk '{printf "%d",$3/1048576;}'`;
47+
disk_free=`echo $sua | awk '{printf "%d",$4/1048576;}'`;
48+
49+
#---[ VGA ] ---------------------------
50+
gpu=''
51+
if which lspci >/dev/null 2>/dev/null; then
52+
gpu="`lspci -mm -v | grep -m 1 -A 2 VGA | tail -n +2 | sed -e 's/Vendor:\t//;s/Device:\t//' | sed -e 's/.*[ ]\[//;s/\].*//' | sed -e 's/, Inc.//;s/ Corporation//;s/ Co.//;s/,Ltd.//' | tr '\n' ' ' | sed -e 's/ $//'`"
53+
fi
54+
55+
#---[ OUTPUT ]------------------------
56+
57+
case "${1}" in
58+
'-l'|'--long')
59+
60+
#---[ LONG VERSION ]--
61+
62+
gpu_line=''
63+
if [ ! -z "${gpu}" ]; then
64+
gpu_line="[gpu] ${gpu}"
65+
fi
66+
67+
# output until EOF, strip leading TAB characters and empty lines
68+
grep -v '^$' <<-EOF
69+
[host] ${host}
70+
[system] ${os}, uptime: ${uptime}, load: ${cpu_load}
71+
[cpu] ${cpu}${cpu_count_notice}, ${cpu_speed} Mhz
72+
${gpu_line}
73+
[memory] ${mem_total} MiB total, ${mem_used} MiB used, ${mem_free} MiB free
74+
[swap] ${swap_total} MiB total, ${swap_used} MiB used, ${swap_free} MiB free
75+
[disk] ${disk_size} GiB total, ${disk_used} GiB used, ${disk_free} GiB free
76+
EOF
77+
;;
78+
*)
79+
#---[ SHORT VERSION ]-
80+
81+
gpu_line=''
82+
if [ ! -z "${gpu}" ]; then
83+
gpu_line="[${gpu}]"
84+
fi
85+
86+
# output until EOF, strip TAB characters
87+
tr -d "\t" <<-EOF
88+
[${host}]
89+
[${os}]
90+
[${cpu}${cpu_count_notice} @ ${cpu_speed} MHz]
91+
${gpu_line}\
92+
[Memory used: ${mem_used}/${mem_total} MiB]
93+
[Swap used: ${swap_used}/${swap_total} MiB]
94+
[Disk used: ${disk_used}/${disk_size} GiB]
95+
[Load ${cpu_load}]
96+
[Uptime ${uptime}]
97+
EOF
98+
;;
99+
esac

0 commit comments

Comments
 (0)