my system configuration


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting my system configuration
# 1  
Old 09-21-2011
my system configuration

Here with I am submitting a script [File attached too], which is made for my use. It may be useful for anyone. I did't given in functions and all..[little lazy]..

I am posting in this forum , because anyone can reply to this thread , for any change/addition.

And yea , suggestions awaiting..Smilie


Code:
#!/bin/bash

#
# System configuration 
# (All most complete information)
# @uther : linuxeverywhere@gmail.com
#

#This script path and name---------------[
if [ `dirname $0` == "." ] ; then
thisScript=`pwd`"/$0"
else
thisScript=$0
fi
#This script path and name---------------[

#-----------check root or any local user-----#
userId=`id -g`
if [ $userId == 0 ]; then

clear
echo ""
echo " System configuration"
echo " ===================="

#System-Info---------------------[
host_name=`hostname`
date_n_time=`date '+%m/%d/%y %H:%M:%S'`
#System-Info---------------------]

#os-details----------------------[
os_installed=`cat /etc/issue | head -1`
os_name=`uname -a`
hw_platform=`uname -i`
if [ $hw_platform == "i386" ]; then
hw_platform="32bit"
fi
if [ $hw_platform == "x86_64" ]; then
hw_platform="64bit"
fi
#os-details----------------------]

#users---------------------------[
no_of_users=`who | wc -l`
users=`users | awk '{ while(++i<=NF) printf (!a[$i]++) ? $i FS : ""; i=split("",a); print "" }'`
#users---------------------------]

#ip-address(s)----------------------[
ip_address=`echo \`ifconfig | grep "inet addr"| grep -v "127.0.0.1" | awk '{print $2}' |cut -d: -f2 \` |tr " " ","`
#ip-address(s)----------------------]

#cpu-info------------------------[
cpu=`grep "model name" /proc/cpuinfo | cut -d: -f2 | head -1`
no_of_cpu=`grep "model name" /proc/cpuinfo | cut -d: -f2 | wc -l`
#cpu-info------------------------]

#RAM and Swap Info------------------------[
Javaversion=`java -version  2>&1 | awk '{print $2$3$4}' |tail -1`
RamInSystem=`echo \`dmidecode --type 17 | grep "Size" | grep "MB" |awk '{print $2}'\``
RAM_total_available=`free -m 2>&1 | awk '{print $4}' | head -2 | tail -1`
RAM_total_cut=`echo $RamInSystem | awk '{print $1+$2+$3+$4+$5}'| awk '{print $1 / 1000}' | bc | cut -d. -f1`
swapInstalled=`cat /proc/swaps | tail -1 | awk '{print $3 / 1000000}' | bc`
swapInstalled_cut=`echo "$swapInstalled"  | cut -d. -f1`
RamMulByTwo=`echo "$RAM_total_cut * 2" | bc`
if [ $RamMulByTwo -le $swapInstalled_cut ]; then
swapOkOrNot=`echo "Yes"`
else
swapOkOrNot=`echo "No. Atleast $RamMulByTwo GB should be there"`
fi
RAM_total_used=`free -m 2>&1 | awk '{print $3}' | head -2 | tail -1`" MB"
countRams=`echo $RamInSystem | wc -w`
RamSize=`echo $RamInSystem | tr " " ","`" MB [$countRams RAM(s)]"
#RAM and Swap Info------------------------]

#HDD Info------------------------[
if [ $userId == 0 ]; then
No_of_HDDs=`fdisk -l 2>&1 | grep Disk | grep -v "identifier" | grep -v "valid partition" | awk '{print $3}' | wc -l`
countHDD=`fdisk -l 2>&1 | grep Disk | grep -v "identifier" | grep -v "valid partition" | awk '{print $3}' | wc -m`
countHDD=`echo $[ $countHDD - 1 ]`
HDD=`fdisk -l 2>&1 | grep "Disk" | grep -v "identifier" | grep -v "valid partition" | awk '{print $3 ""}' | tr "\n" ","| cut -c1-$countHDD`" GB [$No_of_HDDs HDD(s)]"
else
HDD="not configured -deepak"
fi
#HDD Info------------------------]

#Tomcat-Status-----------can be used in tomcatservice file /etc/init.d/tomcat...--------[
tomcat_count=`ps -ef | grep catalina | grep -v "grep catalina" | grep -v "catalina.out"| wc -l`
psid=`ps -ef | grep catalina | grep -v "grep catalina" | grep -v "catalina.out" | awk '{print $2}' | head -1`
if [ $tomcat_count = 1 ]
then
tomcat_status="Running. ( pid "`ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'`")"
KBusedbyTomcat=`pmap $psid 2>&1 | tail -1 | awk '{print $2}' | cut -dK -f1`
elif [ $tomcat_count -gt 1 ]
then
tomcat_status="Not Running (There may be an error. Pid "`ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" |awk '{printf $1 " "}'`")"
else 
tomcat_status="Not Running"
KBusedbyTomcat="0"
fi
#Tomcat-Status-------------------]

#Postgres-Status-------------------[
postgres_count=`ps -ef | grep postgres | grep -v "grep postgres" | wc -l`
if [ $postgres_count -gt 0 ]; then
postgres_status="Running. ( pid "`ps ax --width=1000 | grep "postgres" | grep -v "grep postgres" | awk '{printf $1 " "}'`")"
else
postgres_status="Not Running"
fi
#Postgres-Status-------------------]

#-----------------------------------------IMPORTANT-------------------------------[
if [ $RAM_total_available -lt 50 ]; then
echo -e "\t\t\t\t\t:X: DANGER :X:\n\t\t\t\t\tSystem Running in very low memory : $RAM_total_available MB only"
fi
#-----------------------------------------IMPORTANT-------------------------------]

echo ""
echo " Computer Name                  : $host_name"
echo " Operating System (Name)        : $os_installed"
echo " Operating System (Description) : $os_name"
echo " OS Hardware platform           : $hw_platform"
echo " System Date & Time             : $date_n_time"
echo " IP address(es) given           : $ip_address"
echo " CPU                            :$cpu [$no_of_cpu cpu(s)]"
echo " RAM installed                  : $RamSize"
echo " RAM available                  : $RAM_total_available MB"
echo " Java version                   : $Javaversion"
echo " Swap memory			: $swapInstalled"
echo " Swap memory is enough ?	: $swapOkOrNot"
echo " RAM used                       : $RAM_total_used"
echo " Hard disk(s)                   : $HDD"
echo " Users logged in                : $users (in $no_of_users places)"

echo ""
echo " Tomcat status                  : $tomcat_status"
echo " Memory used by Tomcat          : $KBusedbyTomcat KB"
echo " Postgres status                : $postgres_status"
echo ""

else
echo ""
echo "!!! Please Login as root OR enter root password!!!"
su root -c "$thisScript"
fi

# 2  
Old 09-21-2011
Some comments:

1) We often get the "linux newbie memory freakout" here. A new user may see "56M free" and panic -- rebooting obsessively when free gets low, plugging bizzare and harmful values into /proc/vm to "flush the cache", and sometimes even reformatting just to try and solve an imaginary memory leak. Any decently busy system converts 'free' to 'cache' in short order, which is fine -- cache is as good as free.

2) It'd be better to leave dmidecode out than demand random people run your untested script as root.

3) Run ifconfig with the full path, /sbin/ifconfig, so non-root users can find it.

4) Not everyone has java. Test if java exists before trying to get its version.

5) You can get disk information without root and fdisk, as well as tons of other stuff, via /sys:
Code:
# Sizes and models of all hard drives
TOTAL=0
for X in /sys/class/block/[sh]d[a-z]
do
        D=$(basename ${X})
        read TYPE < ${X}/removable
        read SIZE < ${X}/size
        read MODEL <"${X}/device/model"
        [ "$TYPE" = 0 ] || continue # Ignore removable drives
        set -- ${X}[1-9]* # Set $# to the number of partitions

        TOTAL=$((TOTAL + SIZE))
        echo "$D[1-$#]: $(((SIZE*512)/(1000*1000*1000)))GB $MODEL"
done

echo "Total: $(( (TOTAL*512)/(1000*1000*1000) )) GB"

# MAC addresses of all network cards
for DEV in /sys/class/net/*
do
        D=`basename $DEV`
        [ "$D" = "lo" ] && continue # Ignore loopback
        [ "$D" = "sit0" ] && continue # Ignore ipv6 tunnel

        read MAC < $DEV/address
        echo "$D mac $MAC"
done

# Get some DMI information without needing root
cat /sys/class/dmi/id/* 2>/dev/null


Last edited by Corona688; 09-21-2011 at 04:47 PM..
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 09-21-2011
I could not look all of script but i can say something as far as I look over.Smilie

Code:
RamInSystem=`echo \`dmidecode --type 17 | grep "Size" | grep "MB" |awk '{print $2}'\``
RamInSystem=`dmidecode --type 17 | grep " MB" |awk '{s+=$2}END{print s}'`

Code:
RAM_total_cut=`echo $RamInSystem | awk '{print $1+$2+$3+$4+$5}'| awk '{print $1 / 1000}' | bc | cut -d. -f1`
RAM_total_cut=`echo $RamInSystem|awk '{if ($1>999){x=$1/1000;split(x,a,".");print a[1]} else {print "."$1}}'`

Code:
if [ $RamMulByTwo -le $swapInstalled_cut ]; then
swapOkOrNot=`echo "Yes"`
else
swapOkOrNot=`echo "No. Atleast $RamMulByTwo GB should be there"`
fi
echo|awk -v c=$RamMulByTwo -v d=$Installed_cut '{if (c<=d) printf "%s\n","Yes";else printf "%s\n","No. Atleast $RamMulByTwo GB should be there"}'

Code:
RAM_total_used=`free -m 2>&1 | awk '{print $3}' | head -2 | tail -1`" MB"
RAM_total_used=`free -m 2>&1 | awk 'NR==2 {print $3" MB"}'`

Code:
countRams=`echo $RamInSystem | wc -w`
countRams=`dmidecode --type 17 | grep " MB"|awk 'END{print NR}'`

regards
ygemici
This User Gave Thanks to ygemici For This Post:
# 4  
Old 09-22-2011
Thanks a lot.

I was expecting the same. Surely i will make it. I will re-make including these suggestions.

Any way , waiting for more replies.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Wich tool for check that two system have the same configuration

Hello , On a couple of system I have to check that systems have the same configuration. This system are part of manual cluster but when application are going to switch from one side to another side I would like to be sure I am not going to experience incidents. It is why I wonder if on the web... (2 Replies)
Discussion started by: xavier38450
2 Replies

2. Solaris

system configuration

how to identify if the machine is sun4u ? is this model a sun4u machine ? Model : Sun Ultra 5/10 UPA/PCI (UltraSPARC-IIi 300MHz), (2 Replies)
Discussion started by: sudhiroracle
2 Replies

3. Shell Programming and Scripting

To check the system configuration on Sun solaris

Hi, Could you pls. let me know what is cammand in unix to check the system configuration on Sun solaris. Thanks in advance. Cheers (2 Replies)
Discussion started by: krackjack
2 Replies

4. UNIX for Advanced & Expert Users

Script to get system configuration

Hi, We have >1000 UNIX boxes in our environment with various UNIX flavors like Solaris, HP-UX and Redhat Linux ES 3/4/5. We need to collect their system configuration like - No. of CPUs and their frequencies - RAM Size - No. of HDDs installed and their usage - Exact OS Version and its... (3 Replies)
Discussion started by: prvnrk
3 Replies

5. Shell Programming and Scripting

System Configuration Extraction

Hi All, Im trying to extract a bunch of systems configuration. I have created a file called data.txt and used the below scripts to run extraction of data. Content of data.txt: /etc/passwd /etc/shadow /etc/cron.allow On the Linux terminal, I entered the following commands to execute my... (4 Replies)
Discussion started by: nerd
4 Replies

6. UNIX for Dummies Questions & Answers

Gathering system configuration

Hi there, I have been asked to write a script that gathers enough information on our Sun Solaris machines to be able to rebuild and configure them if they should go pop. My question is does anybody have any suggestions on the files that I need to take a copy of, to ensure that everything is... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

7. UNIX for Dummies Questions & Answers

System boot configuration

On my PC I have two hard disks, the first with Windows 98 SE and the second with Linux Mandrake 8.0 (Traktopel). When I have installed Linux, it has modified the boot record of the 1st HD and it has added a graphic menu (LILO) for selecting the OS to use. By default, if I don't press a key, Linux... (2 Replies)
Discussion started by: robotronic
2 Replies

8. UNIX for Dummies Questions & Answers

How to the configuration of the system

How to know configuration information of the system. like (1) memory assigned for RAM - ? (2) How much is the Hard disk -? (3) processor I used uname and du -k commands. But i couldn't get information about RAM. which command gives this info (3 Replies)
Discussion started by: ds_sastry
3 Replies
Login or Register to Ask a Question