Script printing else condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script printing else condition
# 1  
Old 10-21-2011
Script printing else condition

Please help what is wrong in below script. It is printing else also,

else
echo "DATABASE NOT RUNNING :${i}

=================================================


#!/usr/bin/ksh
set -A DBS $(cat /etc/oratab | grep ":Y" | awk -F : '{print $1}')
set -A RDBS $(ps -ef | grep -i pmon | grep -v grep | awk '{print $NF}' | awk -F _ '{print $3}')
STATUS=1
for i in "${DBS[@]}";do
for j in "${RDBS[@]}";do
if [ ${i} = ${j} ];then
STATUS=0
fi

done

if [ $STATUS -eq 0 ];then
echo "DATABASE RUNNING :${i}
else
echo "DATABASE NOT RUNNING :${i}
fi
done
# 2  
Old 10-21-2011
Code:
#!/usr/bin/ksh
for db in `grep ":Y" /etc/oratab | awk -F":" '{print $1}'`
do
	prunc=`ps -ef | grep -i pmon | awk '{print $NF}' | awk -F _ '{print $3}' | grep -c "${db}"`
	if [ ${prunc} -eq 1 ]
	then
		echo "DATABASE RUNNING[${prunc}]: [${db}]"
	else
		echo "DATABASE NOT RUNNING[${prunc}]: [${db}]"
	fi
done

This User Gave Thanks to felipe.vinturin For This Post:
# 3  
Old 10-21-2011
You are really great. It works. Also it is simple logic. Thanks for your help.
# 4  
Old 10-21-2011
This one is a little bit better, with a few less pipes:
Code:
#!/usr/bin/ksh
for db in `grep ":Y" /etc/oratab | awk -F":" '{print $1}'`
do
	prunc=`ps -ef | grep -c "ora_pmon_${db}"`
	if [ ${prunc} -eq 1 ]
	then
		prunpid=`ps -ef | grep "ora_pmon_${db}" | awk '{print $2}'`
		echo "DATABASE RUNNING[${prunc}]: [${db}] - PID: [${prunpid}]"
	else
		echo "DATABASE NOT RUNNING[${prunc}]: [${db}]"
	fi
done

There's always more than one way to do it! =o)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Condition in bash script

I want get from user and pass these parameters to bash script. script should copy files in user home directory. FYI: each file might be exist or not, might be one of them exist or four of them. Here is my script, it always copy file1 and seems only one of them execute! #!/bin/bash for... (6 Replies)
Discussion started by: indeed_1
6 Replies

2. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

3. Shell Programming and Scripting

Printing symbols with some condition

hi ..all I have an urgency of doing some task so I am posting here...please help i tried this ...its not working properly awk '{if($1>p)print $0;else $1=$2="*";print $0}'pls find attachment my input file is like this 0 25.2 11-Jan-1971 6.45 1040 SU 1 25.2 ... (3 Replies)
Discussion started by: Dona Clara
3 Replies

4. UNIX for Dummies Questions & Answers

While condition in shell script

while do if ;then read driverName else driverName="" fi done can anyone please explain what exactly is happening on 1st line...is it like the conditions being ORed...I have no clue about this. (4 Replies)
Discussion started by: rtagarra
4 Replies

5. Shell Programming and Scripting

Script with variable and condition

Hello newbies question... I just need a script able to launch a command when a condition is matched : #!/bin/ksh SIZ = 'cat /nurp/control.lst|wc -l' if test "$SIZ" -gt 0 then echo 1 else echo 2 fi but I receive errors messages ./t2: SIZ: not found 2 whats wrong ? (5 Replies)
Discussion started by: vdurieu
5 Replies

6. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

7. Shell Programming and Scripting

Condition in script

Hi all, I am writing a script (.sh) which takes backup of database, zip it ftp to remote server and finally mail me to notify. So far this all has been done, however, now I am looking to add notification over each step. Means if any step is failed, then I should get an email and if all goes... (2 Replies)
Discussion started by: viki250
2 Replies

8. Shell Programming and Scripting

Printing records which meet condition using awk

Below is the code nawk -F"|" 'tolower($1) ~ "abc" |"" {if (tolower($2) ~"abc"|"") print$0}' file I want the records from file whose 1st and 2nd field should be either "abc" or "null" I tried but its giving error. Appreciate help (2 Replies)
Discussion started by: pinnacle
2 Replies

9. Shell Programming and Scripting

Help with shell script to check the condition.

:) Hi, I want to script for this scenerio, OSR Settings Scenario : We are looking to find all the *.a files from the following locations in the filesystem of a server. OSR Directories /etc /bin /usr/bin /usr/sbin /var/adm These *.a files should have the permissions on... (12 Replies)
Discussion started by: sakthilinux
12 Replies

10. Shell Programming and Scripting

OR'ing condition in script

Hi, I have the following requirement. I am building a product on linux. The final build executables and libraries are all in different directories. I am writing a release script to collect all these final build items into a directory in /home/$USER/release. I have the following condition: ... (9 Replies)
Discussion started by: vino
9 Replies
Login or Register to Ask a Question