Issue 21 – shell script

#!/bin/bash
clear
echo
#Create a colored header for the section
echo -e “E[33mLINUX”
echo -e “E[33m—————————————————————–”
#Display info about the kernel, distro and uptime, cut commands cut out only the applicable info from output
echo -e “E[34mKernel:        `uname -r`”
echo “Distro:        `cat /etc/issue|tail -n 2|cut –delimiter=” ” -f 1,2`”
echo “Uptime:         `uptime |cut –delimiter=” ” -f 4,5|cut –delimiter=”,” -f 1`”
echo
#Create another colored header for the CPU section
echo -e “E[0mCPU”
echo -e “E[0m—————————————————————–”
#Create a variable to store the name of the CPU model (since it’s a dual core, it will be the same name for both cores.  awk cuts out the name of the CPU, #and the head -n 1 removes the unnecessary duplicates (will work for a quad core too) and the sed command removes the leading blank space before the line.
#the s/^[ t]*// means substitute any leading whitespace (be it a space or a tab) and replace it with nothing.
ModelName=`awk ‘{FS = “:”} /^model name/ {print $2} ‘ /proc/cpuinfo|head -n 1|sed ‘s/^[ t]*//’`
echo -e “E[33mCPU 1:        $ModelName”
echo “Speed of CPU 1:    `grep “cpu MHz” /proc/cpuinfo | cut –delimiter=”:” -f 2|head -n 1|sed ‘s/^[ t]*//’` mhz”
echo “CPU 2:        $ModelName”
echo “Speed of CPU 2:    `grep “cpu MHz” /proc/cpuinfo | cut –delimiter=”:” -f 2|tail -n 1|sed ‘s/^[ t]*//’` mhz”
#Below, the indent command is used to remove any indentation (setting the indentation level to 0 with the -i0 flag).  However, indent isn’t installed by #default, anyone who would like could try to replace it with sed (think of it as a challenge).
let memtotal=`grep “MemTotal” /proc/meminfo | cut -c 12-22 | indent -i0|tail -n 1`/1024
let memfree=`grep “MemFree” /proc/meminfo | cut -c 12-22 | indent -i0|tail -n 1`/1024
let memcache=`grep “Cached” /proc/meminfo | cut -c 12-22 | indent -i0|tail -n 1`
let memcache=$memcache/1024
let memfreetotal=$memfree+$memcache
let memused=$memtotal-$memfreetotal
echo -e “E[32mMemory Used:     $memused MB”
echo “Memory Free:     $memfreetotal MB”
echo “Memory Total:     $memtotal MB”
echo
#Yet another Header
echo -e “E[31mTHEME DETAILS”
echo -e “E[31m—————————————————————–”
tput sgr0 #set colors back to normal in the terminal
#create variables with the various theme names, if you need to remove any just comment the variable out and the echo line pertaining to that variable.
UI=`gconftool-2 -g /desktop/gnome/interface/gtk_theme`
WM=`gconftool-2 -g /apps/metacity/general/theme`
MT=`gconftool-2 -g /desktop/gnome/peripherals/mouse/cursor_theme`
Emerald=`cat ~/.emerald/theme/theme.ini|tail -n 2|cut –delimiter=”=” -f 2|head -n 1`
Icons=`gconftool-2 -g /desktop/gnome/interface/icon_theme`
echo -e “E[36mWM:         $WM”
echo “GTK Theme:     $UI”
echo “Mouse Theme:     $MT”
echo “Emerald Theme:     $Emerald”
echo “Icon Theme:      $Icons”
tput sgr0 #Again, set the colors back to normal in the terminal, otherwise it overflows back to the shell
exit 0 # Exit the program after running

Share it now!

Read Full Circle at:


You can also read Full Circle online at: http://issuu.com/fullcirclemagazine


You can also read Full Circle online via Google Play/Books

Go on Flattr us

All donations go to buying you folks some awesome competition prizes.

Subscribe

You can subscribe to get an email update every time a new issue of the magazine comes out.

Name:

E-mail:


About

Full Circle is a free, independent, monthly magazine dedicated to the Ubuntu family of Linux operating systems. Each month, it contains helpful how-to articles and reader submitted stories.

Full Circle also features a companion podcast, the Full Circle Podcast, which covers the magazine along with other news of interest.