-
-
Notifications
You must be signed in to change notification settings - Fork 674
/
v-list-sys-info
executable file
·114 lines (94 loc) · 3.09 KB
/
v-list-sys-info
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
# info: list system os
# options: [FORMAT]
#
# The function checks available updates for hestia packages.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
format=${1-shell}
# Includes
source $HESTIA/func/main.sh
# Retrieve Hestia Control Panel version number
HESTIA_VERSION=$(grep VERSION $HESTIA/conf/hestia.conf | cut -d '=' -f2 | sed "s|'||g")
HESTIA_RELEASE=$(grep RELEASE_BRANCH $HESTIA/conf/hestia.conf | cut -d '=' -f2 | sed "s|'||g")
# JSON list function
json_list() {
echo '{'
echo ' "sysinfo": {
"HOSTNAME": "'$HOSTNAME'",
"OS": "'$OS'",
"VERSION": "'$VERSION'",
"ARCH": "'$ARCH'",
"HESTIA": "'$HESTIA_VERSION'",
"RELEASE": "'$HESTIA_RELEASE'",
"UPTIME": "'$UPTIME'",
"LOADAVERAGE": "'$LOADAVERAGE'"
}'
echo '}'
}
# SHELL list function
shell_list() {
echo "HOSTNAME OS VER ARCH HESTIA RELEASE UPTIME LA"
echo "-------- -- --- ---- ------ ------- ------ --"
echo "$HOSTNAME $OS $VERSION $ARCH $HESTIA_VERSION $HESTIA_RELEASE $UPTIME $LOADAVERAGE"
}
# PLAIN list function
plain_list() {
echo -e "$HOSTNAME\t$OS\t$VERSION\t$ARCH\t$HESTIA_VERSION\t$HESTIA_RELEASE\t$UPTIME\t$LOADAVERAGE"
}
# CSV list function
csv_list() {
echo "HOSTNAME,OS,VERSION,ARCH,HESTIA,RELEASE,UPTIME,LOADAVERAGE"
echo "$HOSTNAME,$OS,$VERSION,$ARCH,$HESTIA_VERSION,$HESTIA_RELEASE,$UPTIME,$LOADAVERAGE"
}
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Check hostname
HOSTNAME=$(hostname)
# Check OS/Release
if [ -d '/etc/sysconfig' ]; then
if [ -e '/etc/redhat-release' ]; then
OS='CentOS'
VERSION=$(cat /etc/redhat-release |tr ' ' '\n' |grep [0-9])
else
OS="Amazon"
VERSION=$(cat /etc/issue |tr ' ' '\n' |grep [0-9])
fi
else
if [ "$(lsb_release -si)" == "Ubuntu" ] && [ -e '/etc/debian_version' ]; then
OS="Ubuntu"
VERSION=$(grep DISTRIB_RELEASE /etc/lsb-release |cut -f 2 -d '=')
else
distro=$(head -n1 /etc/issue |cut -f 1 -d ' ')
if [ "$distro" = 'Debian' ]; then
OS="Debian"
VERSION=$(cat /etc/debian_version)
else
OS='UNKNOWN'
VERSION='UNKNOWN'
fi
fi
fi
# Check architecture
ARCH=$(arch)
# Check uptime
UPTIME=$(cat /proc/uptime |cut -f 1 -d ' '|cut -f 1 -d .)
UPTIME="$(echo $UPTIME / 60 |bc)"
# Check LoadAverage
LOADAVERAGE=$(cat /proc/loadavg |cut -f 1 -d ' ')
# Check Home Partition usage
HOME_USAGE=$(du -sh /home | cut -f1)
# Listing data
case $format in
json) json_list ;;
plain) plain_list ;;
csv) csv_list ;;
shell) shell_list |column -t ;;
esac
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
exit