Wednesday, March 3, 2010

My .bashrc File Part 2 - Useful System Information

In the last segment I discussed displaying some useful personal information using a function script within my .bashrc file. Today I'll discuss displaying useful system information. I have two funtions which display system information, which is set up very similar to my previous script.

This first script displays my internal IP address and my WAN IP address by simply extracting that information from ifconfig whenever I type "myip" in the terminal. Here is the script.

function myip() # get IP adresses
MY_IP=$(/sbin/ifconfig eth0 awk "/inet/ { print $2 } " sed -e s/addr://) \ MY_ISP=$(/sbin/ifconfig
eth0 awk "/P-t-P/ { print $3 } " sed -e s/P-t-P://)

This displays:

External IP:
Internal IP:

This second function displays my machine statistics, file system space available, memory stats and IP information, when I type "ii" in the terminal. Here is the function:

function ii() # get current host related info
echo -e "\nHello ${RED}$USER"
echo -e "\nSystem information:$NC " ; uname -a
echo -e "\n${RED}Machine stats :$NC " ; uptime
echo -e "\n${RED}Storage stats :$NC " ; df -h grep -v varrun grep -v varlock grep -v udev grep -v\ devshm
echo -e "\n${RED}Memory stats :$NC " ; free -m
echo -e "\n${RED}Local IP Address :$NC" ; ifconfig grep
'inet addr:' grep -v '' cut -d: -f2 awk '{ print $1}'
echo -e "\n${RED}ISP Address :$NC" ; wget -O - -q
echo ""

You'll notice that in this script, my outside WAN IP is pulled from a website instead of from the ifconfig command. Here is the output:

Hello jared

System information:
Linux manti 2.6.24-24-server #1 SMP Fri Sep 18 17:24:10 UTC
2009 i686 GNU/Linux

Machine stats :
10:02:17 up 81 days, 15:14, 10 users, load average: 0.15, 0.38, 0.37

Storage stats :
Size Used Avail Use% Mounted on

/dev/sda1 17G 3.0G 13G 19% /
/dev/sda2 276G 246G 16G 94% /home
/dev/sdb1 187G 146G 32G 82% /media/backup

Memory stats :
total used free shared buffers cached
Mem: 502 492 10 0 37 65
-/+ buffers/cache: 389 113
Swap: 1874 30 1844

Local IP Address :
ISP Address :

I apologize that not everything is lined up correctly, it's due to the layout in blogger. The output lines up fairly cleanly in the terminal.


1 comment:

William Shotts said...

You'll get better results with the layout if you format code and terminal output in a monospaced font such as courier.