myvesta/bin/v-list-sys-info
2018-02-14 17:10:14 +02:00

106 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# info: list system os
# options: [FORMAT]
#
# The function checks available updates for vesta packages.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
format=${1-shell}
# Includes
source $VESTA/func/main.sh
# JSON list function
json_list() {
echo '{'
echo ' "sysinfo": {
"HOSTNAME": "'$HOSTNAME'",
"OS": "'$OS'",
"VERSION": "'$VERSION'",
"ARCH": "'$ARCH'",
"UPTIME": "'$UPTIME'",
"LOADAVERAGE": "'$LOADAVERAGE'"
}'
echo '}'
}
# SHELL list function
shell_list() {
echo "HOSTNAME OS VER ARCH UPTIME LA"
echo "-------- -- --- ---- ------ --"
echo "$HOSTNAME $OS $VERSION $ARCH $UPTIME $LOADAVERAGE"
}
# PLAIN list function
plain_list() {
echo -e "$HOSTNAME\t$OS\t$VERSION\t$ARCH\t$UPTIME\t$LOADAVERAGE"
}
# CSV list function
csv_list() {
echo "HOSTNAME,OS,VERSION,ARCH,UPTIME,LOADAVERAGE"
echo "$HOSTNAME,$OS,$VERSION,$ARCH,$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 ' ')
# Listing data
case $format in
json) json_list ;;
plain) plain_list ;;
csv) csv_list ;;
shell) shell_list |column -t ;;
esac
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit