Skip to content

Commit 7929099

Browse files
committed
List system information
1 parent 525d706 commit 7929099

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

bin/v-list-sys-info

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
# info: list system os
3+
# options: [FORMAT]
4+
#
5+
# The function checks available updates for vesta packages.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
format=${1-shell}
14+
15+
# Includes
16+
source $VESTA/func/main.sh
17+
18+
19+
#----------------------------------------------------------#
20+
# Action #
21+
#----------------------------------------------------------#
22+
23+
# Check hostname
24+
HOSTNAME=$(hostname)
25+
26+
# Check OS/Release
27+
if [ -e '/etc/redhat-release' ]; then
28+
if [ ! -z "$(grep CentOS /etc/redhat-release)" ]; then
29+
OS='CentOS'
30+
else
31+
OS="RHEL"
32+
fi
33+
VERSION=$(cat /etc/redhat-release | tr ' ' '\n' |grep [0-9])
34+
else
35+
if [ -e '/etc/lsb-release' ] && [ -e '/etc/debian_version' ]; then
36+
OS="Ubuntu"
37+
VERSION=$(grep DISTRIB_RELEASE /etc/lsb-release| cut -f 2 -d '=')
38+
else
39+
distro=$(head -n1 /etc/issue | cut -f 1 -d ' ')
40+
if [ "$distro" = 'Debian' ]; then
41+
OS="Debian"
42+
VERSION=$(cut /etc/debian_version)
43+
else
44+
OS='UNKNOWN'
45+
VERSION='UNKNOWN'
46+
fi
47+
fi
48+
fi
49+
50+
# Check architecture
51+
ARCH=$(arch)
52+
53+
# Check uptime
54+
UPTIME=$(cat /proc/uptime |cut -f 1 -d ' '|cut -f 1 -d .)
55+
UPTIME="$(echo $UPTIME / 3600 | bc)"
56+
57+
# Check LoadAverage
58+
LOADAVERAGE=$(cat /proc/loadavg |cut -f 1 -d ' ')
59+
60+
# Create tmp file
61+
tmp_file=$(mktemp)
62+
63+
# Define key/value pairs
64+
str="HOSTNAME='$HOSTNAME' OS='$OS' VERSION='$VERSION' ARCH='$ARCH'"
65+
str="$str UPTIME='$UPTIME' LOADAVERAGE='$LOADAVERAGE'"
66+
67+
# Defining config
68+
echo -e "$str" > $tmp_file
69+
conf=$tmp_file
70+
71+
# Defining fileds to select
72+
fields="\$HOSTNAME \$OS \$VERSION \$ARCH \$UPTIME \$LOADAVERAGE"
73+
74+
# Listing services
75+
case $format in
76+
json) json_list ;;
77+
plain) nohead=1; shell_list ;;
78+
shell) shell_list | column -t ;;
79+
*) check_args '1' '0' 'USER [FORMAT]'
80+
esac
81+
82+
rm -f $tmp_file
83+
84+
#----------------------------------------------------------#
85+
# Vesta #
86+
#----------------------------------------------------------#
87+
88+
exit

0 commit comments

Comments
 (0)