LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-16-2010, 04:17 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
Cool Script to monitor CPU information.


I have written little script to check the CPU performance of the machine.
Request you to contribute your comments on the same.

Feel free to add your own scriptlet to make it better.

I have decided to call it as doctortux

I have decided to run the script in two mode
1)Interactive.(Not yet included in script)
2)Automatic.(currently giving CPU information.)

Automatic mode ( -a ) (default):This mode shoudnt ask any input from user and should run automatically.

Interactive mode (-i) : This mode should ask user for input .

Code:
##############################Option Check###############################
#!/bin/bash

#########################UPTIME########################################
fn_uptimeinfo()
{
echo "Machine Uptime Information:"
echo -e "\033[32m uptime"
tput sgr0                    #restores the terminal settings to normal.
uptime
echo "Command Description:"
echo "<current time> <Uptime since> <hour:min>"
echo "Number of users logged in to machine"
echo "load average <for last one minute>,<for last 5 minutes>,<for last 15 minutes>"
echo "________________________________________________________________"
}
fn_terminalinfo()
{
echo "Terminal Information:"
echo -e "\033[32m w"
tput sgr0
w
echo "________________________________________________________________"
}
#################################################################
######################CPU INFO########################################
fn_cpuinfo()
{
echo -e "\033[32m cat /proc/cpuinfo"
tput sgr0
cat /proc/cpuinfo
echo "________________________________________________________________"
}
fn_cpueaterprocess()
{
echo "Top 10 C.P.U Consumer Processes:"
echo -e "\033[32m ps -auxf | sort -nr -k 3 | head -10 "
tput sgr0
ps -auxf | sort -nr -k 3 | head -10
echo "________________________________________________________________"
}
######################################################################
#########################Memory Information###########################
fn_meminfo()
{
echo -e "\033[32m cat /proc/meminfo"
tput sgr0
cat /proc/meminfo
echo "________________________________________________________________"
echo -e "\033[32m free -m"
tput sgr0
free -m
echo "________________________________________________________________"
}

fn_memeaterprocess()
{
echo "Top 10 Memory Consumer Processes:"
echo -e "\033[32m ps -auxf | sort -nr -k 4 | head -10 "
tput sgr0
ps -auxf | sort -nr -k 4 | head -10
echo "________________________________________________________________"
}
######################################################################
#######################Disk Information###############################
fn_diskinfo()
{
echo "Disk Utilization"
echo -e "\033[32m df -h"
tput sgr0
df -h
echo "________________________________________________________________"
}
fn_partitioninfo()
{
echo "Disk Partition Information"
echo -e "\033[32m cat /proc/partitions"
tput sgr0
cat /proc/partitions
echo "________________________________________________________________"
}
######################################################################
fn_automatic()
{
echo "########CPU Information########"
fn_uptimeinfo
fn_terminalinfo
fn_cpuinfo
fn_cpueaterprocess
echo "########Memory Information########"
fn_meminfo
fn_memeaterprocess
echo "########Disk Information########"
fn_diskinfo
fn_partioninfo
}
if [ $# -eq 0 ]
then
  echo "Automatic Mode Selected"
  fn_automatic
else
  while getopts ai option 2>/dev/null
  do
    case "$option" in
      a) echo "Automatic Mode Selected"
         fn_automatic
         echo "Thanks";;
      i) echo "Interacive Mode Selected";;
      ?) echo "Please select proper option"
         echo list of available options
         -a automatic -i interactive ;;
    esac
  done
fi

Last edited by pinga123; 07-16-2010 at 05:48 AM.
 
Old 07-16-2010, 05:50 AM   #2
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
What else can be included?. Also want to know how would i include network information in the script?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getting cpu information 32/64 bit laucian Linux - Hardware 24 10-14-2013 03:23 PM
script to monitor memory and cpu usage s_linux SUSE / openSUSE 3 07-23-2009 02:03 PM
CPU and Memory information DavidDiggs Linux - Hardware 6 03-20-2008 08:36 PM
CPU information : how is it possible?? sachinh Linux - Server 6 06-06-2007 07:04 AM
CPU run information cygnus-x1 Other *NIX 3 05-15-2007 11:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration