I am new to shell scripting. My question is
How to grep exact pattern from a variable in UNIX.
This is the scenario.
In the present server there are 3 oracle databases up and running, which are HRM83DEV, HRM83TST, HRM83CFG. There is no database/s called HRM83LOG, HRM.
This is what I wrote in the shell script
=======================
# script name shtest
if [ X$1 != X ]; then
DBNAME=$1
export DBNAME
else
echo "Database name must be specified as a parameter"
exit
fi
ECH=`ps -fu oracle | grep $DBNAME |grep -c ora_`
if [ "$ECH" = "0" ]; then
echo "The database is not UP and RUNNING, not able to perform backup"
exit
fi
======================
When I Run the script
1. shtest HRM83DEV
(no output, whcih is fine because I did not give any dispaly message)
2. shtest HRM83LOG
The database is not UP and RUNNING, not able to perform backup
3. shtest HRM
(no output like 1st run)
in the 3rd run I am getting nothing. I would like to get as like 2nd run
"The database is not UP and RUNNING, not able to perform backup".
I understand
ps -fu oracle | grep $DBNAME |grep -c ora_ will search the patter starts with H and on.....
I appreciate if anybody help me on this to grep exact pattern search.
Thank you,