From 7929099751c0f2edc6b3eb548558ffc2c5fe7d99 Mon Sep 17 00:00:00 2001 From: Serghey Rodin <serghey.rodin@gmail.com> Date: Tue, 22 Oct 2013 15:22:53 +0300 Subject: [PATCH] List system information --- bin/v-list-sys-info | 88 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 bin/v-list-sys-info diff --git a/bin/v-list-sys-info b/bin/v-list-sys-info new file mode 100755 index 00000000..346e07dd --- /dev/null +++ b/bin/v-list-sys-info @@ -0,0 +1,88 @@ +#!/bin/bash +# info: list system os +# options: [FORMAT] +# +# The function checks available updates for vesta packages. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +format=${1-shell} + +# Includes +source $VESTA/func/main.sh + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Check hostname +HOSTNAME=$(hostname) + +# Check OS/Release +if [ -e '/etc/redhat-release' ]; then + if [ ! -z "$(grep CentOS /etc/redhat-release)" ]; then + OS='CentOS' + else + OS="RHEL" + fi + VERSION=$(cat /etc/redhat-release | tr ' ' '\n' |grep [0-9]) +else + if [ -e '/etc/lsb-release' ] && [ -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=$(cut /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 / 3600 | bc)" + +# Check LoadAverage +LOADAVERAGE=$(cat /proc/loadavg |cut -f 1 -d ' ') + +# Create tmp file +tmp_file=$(mktemp) + +# Define key/value pairs +str="HOSTNAME='$HOSTNAME' OS='$OS' VERSION='$VERSION' ARCH='$ARCH'" +str="$str UPTIME='$UPTIME' LOADAVERAGE='$LOADAVERAGE'" + +# Defining config +echo -e "$str" > $tmp_file +conf=$tmp_file + +# Defining fileds to select +fields="\$HOSTNAME \$OS \$VERSION \$ARCH \$UPTIME \$LOADAVERAGE" + +# Listing services +case $format in + json) json_list ;; + plain) nohead=1; shell_list ;; + shell) shell_list | column -t ;; + *) check_args '1' '0' 'USER [FORMAT]' +esac + +rm -f $tmp_file + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit