Search This Blog

Monday, August 30, 2010

Date ( Linux system)

Change System Date:

There are many ways to change the system date in linux but i think following method is bit easier than others.

# date -s "31 JAN 2009 22:19:53"
-s option used to set the date.


In every case above example is sufficient .However you can use below commands for your knowledge.

# date +%T -s "23:20:57"

# date +%T%p -s "11:20:57PM"

Display Date in different format:

I would recommend to use following format while using date variable in your script.

#date '+%F-%I-%M-%S-%p'
2011-04-01-10-25-33-AM

-F : full date same as %Y-%m-%d
-I : hour (01..12)
-M : minute (00..59)
-S : second (00..60)
-p : localeĆ¢s equivalent of either AM or PM; blank if not known

Coming soon...

Please Leave us with your comments and Queries/Suggestions.
I will try to reply asap.

Cut command

cut command

Description:
Usage :
1)Cut command is mostly use to display columns from a file.
for example if a file contains a row column structure you can display
a column of file specifying column number (Starting with one for First column) using cut command.
2)It can also be used to display a given number of characters from each line of file.

Lets create a sample file (cut_sample.txt) for use.

Student Subject MarksObtained
Jack Spanish 80
Jill English 20
Krishna Gujrathi 30

Note:
our sample file contains 3 columns namely (Student,Subject,MarksObtained)
Each field is seperated by " "(a space).

1) cut command to display columns from a file.
-d is used to specify a delimeter(here the delimeter is a character that seperates
one field from other).A delimeter in above case is a space.
-f is used to specify the field name to be displayed.

Example 1:

# cut -d" " -f 1 cut_sample.txt
Student
Jack
Jill
Krishna

Example 2:

# cut -d" " -f 1,2 cut_sample.txt
Student Subject
Jack Spanish
Jill English
Krishna Gujrathi


2) cut command to display a given number of characters from each line of file.


# cut -c 1-8 cut_sample.txt
Student
Jack Spa
Jill Eng
Krishna

-c is used to specify characters in range 1-8.
In above example 8 character from each lines are displayed from file starting from 1st character .

Use following cut command to display the name of users in the system.
cut -d: -f1 /etc/passwd

Please Leave us with your comments and Queries/Suggestions.
I will try to reply asap.

Friday, August 27, 2010

How to display specific line of file specifying line number.

How to display specific line of file specifying line number.

#awk 'NR==2{print $0}' filename

This will display 2nd line of file named filename.

Another way of doing the same thing (compact one)

#awk 'NR==2' filename

1 More (complex one)

#head -2 filename | tail -1

More will be coming soon.

Please Leave us with your comments and Queries/Suggestions.
I will try to reply asap.

Monday, August 23, 2010

Linux Administration

Today i have decided to give a try on Linux administration.

Not to use root account anymore:
First all all i will make a firm decision not to use root account for my daily purpose.
How how do i do my daily task?
I will make two users named admin and worker.
Admin:
Admin user will be given admin privilege to do Admin specific tasks.
Worker:
Normal user of the machine, who is restricted from admin tasks.
Step 1:
Create two users:
Login with root
# useradd admin
# passwd admin
Changing password for user admin.
New UNIX password:
BAD PASSWORD: it is too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
# useradd worker
# passwd worker
Changing password for user worker.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

Now its time to give Admin user some more privileges than worker user.
Login with root user.

Just keep the backup of /etc/sudoers file using

#cp /etc/sudoers /etc/sudoers.old

type
#visudo in command prompt.(This will modify /etc/sudoers file.This command is better way to modify /etc/sudoers than issuing vi /etc/sudoers .)

Modify the file accordingly
## User Aliases
## These aren't often necessary, as you can use regular groups
## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
## rather than USERALIAS

User_Alias ADMINS = admin

## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL

%admin ALL=(ALL) ALL

save it using esc :wq.


Now you have added admin user in sudoers file with all command execution rights.
Note : visudo is a command line utility to edit /etc/sudoers file.
Its recommended to avoid vi editor.

Now its time to check if whatever is done is working or not.

Lets open two separate terminals.
one for admin user and one for worker user.
Now try to run any command which need root privileges to run.(I m using ifconfig here).
[admin@localhost ~]$ ifconfig
-bash: ifconfig: command not found
[worker@localhost ~]$ ifconfig
-bash: ifconfig: command not found
As you observe both users are unable to run the command.

With admin terminal type following.
#/sbin/ifconfig
It will display the output as admin user is added in sudoer file with all command privilege.
The same can't be done with worker user.

Sunday, August 22, 2010

Robust Scripting.

In This blog entry i will be focusing more on How to build a robust shell script.

According to me writing a script that actually works and writing a robust script that actually work has two different meaning.

So lets try to start writing a robust script.

A good article over writing a robust script can be found in following url.

http://www.davidpashley.com/articles/writing-robust-shell-scripts.html

You can also find following post useful while writing a robust script.

Safest way of comparing values using Variable.

Wednesday, August 18, 2010

Oracle XE installation

Installation of Oracle XE and configuration.

• If you downloaded the oracle-xe-univ-10.2.0.1-1.0.i386.rpm executable, you need to enter following command.
# rpm -ivh downloads/oracle-xe-univ-10.2.0.1-1.0.i386.rpm

The installation displays a status of its progress.
• When prompted, run the following command:
# /etc/init.d/oracle-xe configure




Oracle Database 10g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 10g Express
Edition. The following questions will determine whether the database should
be starting upon system boot, the ports it will use, and the passwords that
will be used for database accounts. Press to accept the defaults.
Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]:8888

Specify a port that will be used for the database listener [1521]:1521

Specify a password to be used for database accounts. Note that the same
password will be used for SYS and SYSTEM. Oracle recommends the use of
different passwords for each database account. This can be done after
initial configuration:
Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]

Starting Oracle Net Listener...Done
Configuring Database...Done
Starting Oracle Database 10g Express Edition Instance...Done
Installation Completed Successfully.
To access the Database Home Page go to http://127.0.0.1:8888/apex

You have now installed Oracle XE on your Linux machine.

For Installation,Documentation and Download you may refer following link .

http://www.oracle.com/technology/software/products/database/xe/files/install.102/b25144/toc.htm#CIHHJEHF

Tuesday, August 17, 2010

This Tutorial is divided into 2 part:

1)Install Database on Linux Machine.
2)Write a Logic (Script to Insert data into Database).


1)Install Database on Linux Machine.

The below tutorial assumes you have oracle database(oracle xe,oracle 9i,10g) installed on your system.
Operating system(Linux):
This should work on Most of linux distributions but for testing purpose i have used OEL(Oracle Enterprise Linux).
# lsb_release -a
LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: EnterpriseEnterpriseServer
Description: Enterprise Linux Enterprise Linux Server release 5.2 (Carthage)
Release: 5.2
Codename: Carthage
# uname -a
Linux 2.6.18-92.el5 #1 SMP Fri May 23 22:17:30 EDT 2008 i686 i686 i386 GNU/Linux.

This is tested using ORACLE XE as a database but for other oracle databases it should work.
Installation steps:

Installation of Oracle XE and configuration.
Make sure your distribution supports rpm installation.
Choose suitable oracle-xe installable for your distribution.
I have selected following rpm.
oracle-xe-univ-10.2.0.1-1.0.i386.rpm

If you downloaded the oracle-xe-univ-10.2.0.1-1.0.i386.rpm executable, you would enter this command:
$ rpm -ivh downloads/oracle-xe-univ-10.2.0.1-1.0.i386.rpm

The installation displays a status of its progress.
When prompted, run the following command:
$ /etc/init.d/oracle-xe configure

Oracle Database 10g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 10g Express
Edition. The following questions will determine whether the database should
be starting upon system boot, the ports it will use, and the passwords that
will be used for database accounts. Press to accept the defaults.
Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]:8888

Specify a port that will be used for the database listener [1521]:1521

Specify a password to be used for database accounts. Note that the same
password will be used for SYS and SYSTEM. Oracle recommends the use of
different passwords for each database account. This can be done after
initial configuration:
Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]

Starting Oracle Net Listener...Done
Configuring Database...Done
Starting Oracle Database 10g Express Edition Instance...Done
Installation Completed Successfully.
To access the Database Home Page go to http://127.0.0.1:8888/apex

For Installation guide please refer.

http://www.oracle.com/technology/software/products/database/xe/files/install.102/b25144/toc.htm#CIHHJEHF

export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=XE(Default instance after installation you can change it as per your installation )


2)Write a Logic (Script to Insert data into Database).

I have used following references to accomplish the task.

http://www.thegeekstuff.com/2010/07/unix-shell-script-to-execute-oracle-sql-query/
http://www.orafaq.com/wiki/SQL*Loader_FAQ


Make sure you set a proper path for ORACLE_HOME and ORACLE_SID

export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=XE

use following script to execute command from bash script.
To get the basic understanding of how to connect to database and execute the command is given in below script.

#!/bin/bash
# Validate the value of ORACLE_HOME #
# If ORACLE_HOME is empty #

if [ -z $ORACLE_HOME ]
then
echo "Set the ORACLE_HOME variable"
exit 1
fi

# If ORACLE_HOME doesn't exist #
if [ ! -d $ORACLE_HOME ]
then
echo "The ORACLE_HOME $ORACLE_HOME does not exist"
exit 1
fi

# Validate the value of ORACLE_SID #
if [ -z $ORACLE_SID ]
then
echo "Set the ORACLE_SID variable"
exit 1
fi

SID=`ps -ef|grep smon|grep -v grep|awk '{print $8}'`

if [ 'xe_smon_'$ORACLE_SID != $SID ] ; then
echo "ORACLE_SID IS NOT SET"
exit 1
fi


# Enter the username and password to login to oracle #
echo "Enter the username"
read username

echo "Enter password"
stty -echo
read password
stty echo

# Get the query , no validation applied for query #
echo "Enter the query"
read query
# Login and execute the query.
echo "set feedback off verify off heading off pagesize 0
$query
exit" | $ORACLE_HOME/bin/sqlplus -s $username/$password | while read output ;
do
echo $output
done

output:
# databaseconnect.sh
Enter the username
lightweight
Enter password
Enter the query
select table_name from tabs;
LIGHT_INVENTORY
LIGHT_CRED
HTMLDB_PLAN_TABLE
LIGHT_ROLE

Additional Information:(Source :http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/bourne/node46.html)
Little Drawback of below script:
You will need to have a different for different oracle products.
This is because they maintain different naming convention for the process.
in case of xe they reffer it as xe_smon_
where as other distribution reffer it as ora_smon_

For Oracle XE installation.(Tested and working fine)

SID=`ps -ef|grep smon|grep -v grep|awk '{print $8}'`

if [ 'xe_smon_'$ORACLE_SID != $SID ] ; then
echo "ORACLE_SID IS NOT SET"
exit 1
fi

For Other Installation(Not Tested but should work.)

SID=`ps -ef|grep smon|grep -v grep|awk '{print $8}'`

if [ 'ora_smon_'$ORACLE_SID != $SID ] ; then
echo "ORACLE_SID IS NOT SET"
exit 1
fi

stty -echo: Passwords
If the script requires the input of a ``secret" string, the string typed from the keyboard should not be displayed on the screen. To stop the display of the characters typed,

# stty -echo

may be used.

To resume echoing of the characters,

#stty echo

is used.

#!/bin/sh
echo -e "Please enter your passcode: \c"
stty -echo
read PASSCODE
stty echo
echo "The passcode was not seen when typed."


However to supply output of bash command into database i have written seperate script.
Description:
This command take a output of vmstat command and insert cpu related information into the database.

Grep Command.

To understand grep We will create a small file as Gandhi.txt.
#touch Gandhi.txt
Above statement will create a file called Gandhi.txt

Post the following lines in a file(Gandhi.txt).
#vi BhagatSingh.txt
press key i for insert copy the text below .and paste it into the file using rightclick
Save the file by pressing esc and then typing :wq

************************************************************
Bhagat Singh, a Sandhu Jat, was born on 28 September 1907 to Kishan Singh and Vidyavati at Chak No. 105, GB, Banga village, Jaranwala Tehsil in the Lyallpur district of the Punjab Province of British India.
In 1923, Bhagat Singh joined the National College in Lahore
Bhagat Singh, Rajguru and Sukhdev were sentenced to death in the Lahore conspiracy case and ordered to be hanged on 24 March 1931.
The execution of Bhagat Singh, Rajguru and Sukhdev were reported widely by the press, especially as they were on the eve of the annual convention of the Congress party at Karachi. Gandhi faced black flag demonstrations by angry youths who shouted "Down with Gandhi". The New York Times reported:
    A reign of terror in the city of Cawnpore in the United Provinces and an attack on Mahatma Gandhi by a youth outside Karachi were among the answers of the Indian extremists today to the hanging of Bhagat Singh and two fellow-assassins.
************************************************************

Let us use some grep commands to get answer to following questions .
When was Bhagat Singh born?
What year was Bhagat Singh born?

You know the only file in your system that has any information about Bhagat Singh is BhagatSingh.txt So you type following command to get the birth date of Bhagat Singh.

# grep born BhagatSingh.txt
Bhagat Singh, a Sandhu Jat, was born on 28 September 1907 to Kishan Singh and Vidyavati at Chak No. 105, GB, Banga village, Jaranwala Tehsil in the Lyallpur district of the Punjab Province of British India.

Now lets print all lines from files with word Bhagat in it.
# grep bhagat BhagatSingh.txt
Surprised of getting nothing as output.
Well this is because grep without -i option ,considered case sensitive.
In our example we have used word gandhi as search parameter.
Now try the same with Gandhi word.(Notice capital letter G).

# grep Bhagat BhagatSingh.txt
Bhagat Singh, a Sandhu Jat, was born on 28 September 1907 to Kishan Singh and Vidyavati at Chak No. 105, GB, Banga village, Jaranwala Tehsil in the Lyallpur district of the Punjab Province of British India.
In 1923, Bhagat Singh joined the National College in Lahore
Bhagat Singh, Rajguru and Sukhdev were sentenced to death in the Lahore conspiracy case and ordered to be hanged on 24 March 1931.
The execution of Bhagat Singh, Rajguru and Sukhdev were reported widely by the press, especially as they were on the eve of the annual convention of the Congress party at Karachi. Gandhi faced black flag demonstrations by angry youths who shouted "Down with Gandhi". The New York Times reported:
    A reign of terror in the city of Cawnpore in the United Provinces and an attack on Mahatma Gandhi by a youth outside Karachi were among the answers of the Indian extremists today to the hanging of Bhagat Singh and two fellow-assassins.

This time Mission Successful. :)

I know what you might be thinking at this stage.
Do i always need to remember the exact Case while searching through files.
Well the answer is No*.
(*:Provided you use option i)

Lets try the same example with word gandhi (Notice all small letters).
# grep -i bhagat BhagatSingh.txt
Bhagat Singh, a Sandhu Jat, was born on 28 September 1907 to Kishan Singh and Vidyavati at Chak No. 105, GB, Banga village, Jaranwala Tehsil in the Lyallpur district of the Punjab Province of British India.
In 1923, Bhagat Singh joined the National College in Lahore
Bhagat Singh, Rajguru and Sukhdev were sentenced to death in the Lahore conspiracy case and ordered to be hanged on 24 March 1931.
The execution of Bhagat Singh, Rajguru and Sukhdev were reported widely by the press, especially as they were on the eve of the annual convention of the Congress party at Karachi. Gandhi faced black flag demonstrations by angry youths who shouted "Down with Gandhi". The New York Times reported:
    A reign of terror in the city of Cawnpore in the United Provinces and an attack on Mahatma Gandhi by a youth outside Karachi were among the answers of the Indian extremists today to the hanging of Bhagat Singh and two fellow-assassins.

-i option is used to ignore cases.


Lets assume you know the birth date of Bhagat Singh and more interested in knowing other facts about him.
Following command will help you get other information .

below command will display all lines except the lines containing born word in it.

# grep -v born BhagatSingh.txt
In 1923, Bhagat Singh joined the National College in Lahore
Bhagat Singh, Rajguru and Sukhdev were sentenced to death in the Lahore conspiracy case and ordered to be hanged on 24 March 1931.
The execution of Bhagat Singh, Rajguru and Sukhdev were reported widely by the press, especially as they were on the eve of the annual convention of the Congress party at Karachi. Gandhi faced black flag demonstrations by angry youths who shouted "Down with Gandhi". The New York Times reported:
    A reign of terror in the city of Cawnpore in the United Provinces and an attack on Mahatma Gandhi by a youth outside Karachi were among the answers of the Indian extremists today to the hanging of Bhagat Singh and two fellow-assassins.

-v is a option used to accomplish such tasks.

Other usage.
-n to display line number.
# grep -vn born BhagatSingh.txt
2:In 1923, Bhagat Singh joined the National College in Lahore
3:Bhagat Singh, Rajguru and Sukhdev were sentenced to death in the Lahore conspiracy case and ordered to be hanged on 24 March 1931.
4:The execution of Bhagat Singh, Rajguru and Sukhdev were reported widely by the press, especially as they were on the eve of the annual convention of the Congress party at Karachi. Gandhi faced black flag demonstrations by angry youths who shouted "Down with Gandhi". The New York Times reported:
5:    A reign of terror in the city of Cawnpore in the United Provinces and an attack on Mahatma Gandhi by a youth outside Karachi were among the answers of the Indian extremists today to the hanging of Bhagat Singh and two fellow-assassins.

-e
Incase you dont want to read anything about his birth and hanging you may use below command.
# grep -vn -e born -e hanging BhagatSingh.txt
2:In 1923, Bhagat Singh joined the National College in Lahore
3:Bhagat Singh, Rajguru and Sukhdev were sentenced to death in the Lahore conspiracy case and ordered to be hanged on 24 March 1931.
4:The execution of Bhagat Singh, Rajguru and Sukhdev were reported widely by the press, especially as they were on the eve of the annual convention of the Congress party at Karachi. Gandhi faced black flag demonstrations by angry youths who shouted "Down with Gandhi". The New York Times reported:


-c  To count the number of matches
# grep -vi -c born BhagatSingh.txt
4


There are many other usage of grep which can be included but the main purpose of this article was to make you aware of its common and widely used syntax.
a good article over basic grep command can be found here.
http://www.thegeekstuff.com/2009/03/15-practical-unix-grep-command-examples/
Expressions that can be used with greps are explained here.
http://www.thegeekstuff.com/2011/01/regular-expressions-in-grep-command/?utm_source=feedburner&utm_medium=email&utm_campaign=Feed%3A+TheGeekStuff+%28The+Geek+Stuff%29

Monday, August 16, 2010

CPU Monitoring(Doctortux)

Following command are usefull for monitoring cpu performance so they are included in the script.

#uptime

The above command helps us find the important aspect of the machine which is How long the machine is been running? in other world when did it start running?
The more the uptime the slower the performance.

#w

The above command helps to determine how many users are logged into the system.
The more the sessions the slower the performance.

#ps auxf | sort -nr -k 3 | head -10

The above command helps to determine the top 10 processes affecting cpu utilization.


#cat /proc/cpuinfo

The above command gives you information about cpu of machine.

Please Leave us with your comments and Queries/Suggestions.
I will try to reply asap.

Bash and Database connectivity.

Install Database as described in below link:

http://learnlinuxwithrohan.blogspot.com/2010/08/oracle-xe-installation.html

Prerequisite:
Set following variables.

export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=XE


Description:
Script connect to the database and execute the command .


#!/bin/bash

# Validate the value of ORACLE_HOME #
if [ -z $ORACLE_HOME ]
then
echo "Set the ORACLE_HOME variable"
exit 1
fi

# If ORACLE_HOME doesn't exist #
if [ ! -d $ORACLE_HOME ]
then
echo "The ORACLE_HOME $ORACLE_HOME does not exist"
exit 1
fi

# Validate the value of ORACLE_SID #
if [ -z $ORACLE_SID ]
then
echo "Set the ORACLE_SID variable"
exit 1
fi

#Get SID for the database.

SID=`ps -ef|grep smon|grep -v grep|awk '{print $8}'`

if [ 'xe_smon_'$ORACLE_SID != $SID ] ; then
echo "ORACLE_SID IS NOT SET"
exit 1
fi


# Enter the username and password to login to oracle #
echo "Enter the username"
read username

echo "Enter password"
stty -echo
read password
stty echo
# Get the query , no validation applied for query #
echo "Enter the query"
read query

# Login and execute the query.
echo "set feedback off verify off heading off pagesize 0
$query
exit" | $ORACLE_HOME/bin/sqlplus -s $username/$password | while read output ;
do
echo $output
done

Output:



More will be coming soon.

Wednesday, August 11, 2010

Future plan

To enhance doctortux i have following plans.

Refer following link and try to incorporate most of functionality into the script.


http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html

Monday, August 9, 2010

Actual script( Doctortux)

After a long discussion with various forums i have decided to name it as doctortux.

I m going to post modified content of Performance monitoring script.


#######################################################################
#!/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 " "
echo "Number of users logged in to machine"
echo "load average ,,"
echo "________________________________________________________________"
}
fn_terminalinfo()
{
echo "Terminal Information:"
echo -e "\033[32m w"
tput sgr0
w
echo "________________________________________________________________"
}
#################################################################
#####################CONNECTION INFO############################
fn_numberofconnection()
{
echo "Connection Information"
echo -e "\033[32m netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | uniq"
tput sgr0
netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | uniq
}
#################################################################
######################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_partitioninfo
echo "#######Connection Information#######"
fn_numberofconnection
}
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
echo "-a automatic -i interactive" ;;
esac
done
fi

Find Command.

Usage:
1)Find a file or folder with their name.


Following command comes handy when you forget the location of file or folder with their exact name.


Following command will search file or folder named mnt throughout the filesystem.


#find / -name mnt


If you are searching for a directory and not a file it would be better if you use a type filter as below.

#find / -type d -name mnt
/mnt

Similarly,
If you are searching for a file and not a directory it would be better if you use a type filter as below.

#
find / -type f -name mnt
(note : Since there is no file with name as mnt nothing will get displayed)

Monday, August 2, 2010

Process monitoring.

use following command to check whether the process exists or not.
#
kill -0


Example:

# kill -0 5071
[root@Localhost ~]# echo $?
0
[root@
Localhost ~]# kill -0 5169
-bash: kill: (5169) - No such process
[root@
Localhost ~]# echo $?
1

Arguments in scripts.

How do you refer to the arguments passed to a shell script?
Answer - $1, $2 and so on. $0 is your script name.


How do you find out the number of arguments passed to the shell script?
Answer - $#


Please Leave us with your comments and Queries/Suggestions.
I will try to reply asap.