Hello,

I'm trying to get this piece of script working, but I'm having an issue on my script. The
if [ $DEV_ORA -eq 0 ] is not get run when I run my script. I do not know what I'm doing wrong here. Basically I trying to run the second if "ORA_ASM" is found on the $DEV_ORA.

Thanks a lot guys

#!/bin/bash

DEV_ORA=$( grep -ic ORA /etc/multipath.conf )

# RH5 ORA_ASM
if grep -q -i "release 5" /etc/redhat-release
then
    echo "Red Hat Release 5"
    ls -l /dev/mapper/mpath* | egrep -v "mpath0|p1" | awk '{print $10}'> /tmp/dump.txt
        if [ $DEV_ORA -eq 0 ]
        then
            ls -l /dev/mapper/ORA* | grep -v p1 | awk '{print $10}' >> /tmp/dump.txt
            echo "Found Oracle ASM DISK"
fi

# RH6 ORA_ASM
if grep -q -i "release 6" /etc/redhat-release
then
    echo "Red Hat Release 6"
    ls -l /dev/mapper/mpath* | egrep -v "mpath0|mpatha|p1" | awk '{print $9}'> /tmp/dump.txt
        if [ $DEV_ORA -eq 0 ]
        then
            ls -l /dev/mapper/ORA*|grep -v p1 |awk '{print $9}'>> /tmp/dum.txt
            echo "Found Oracle ASM DISK"
else
    echo "Running neither RHEL6.x nor RHEL 5.x !"
fi

Over 30 years of writing scripts and debugging code that I and others have written, I find it makes it easier if you simply echo (or print) the variables as you go through the code. If right before your test echo the variable and you will know two things: 1) it made it to the line before the test and 2) what the valuse of the variable is right before the test.
How can you claim that if is not working when you have not examined what is being tested....

You can always comment out the lines later when you go to production.

    ls -l /dev/mapper/mpath* | egrep -v "mpath0|p1" | awk '{print $10}'> /tmp/dump.txt
        echo "$DEV_ORA"
        if [ $DEV_ORA -eq 0 ]
        then

rch1231,

I really appreacited your input on this script. I been trying to use echo and "bash -x script" to debug my script, but for some reason I cannot get it to work. It seems that my if statement is wrong. I just need a little of input I know something I'm doing wrong on my statement.

Thanks a lot.

Have you tried:

        if [ "$DEV_ORA" -eq 0 ]
        then

Also on line 23 should the output file be /tmp/dump.txt like the others?
and what is the output of
grep -ic ORA /etc/multipath.conf

The output of grep -ic ORA /etc/multipath.conf
58
I edited the script and I still having issues. The ORA statement is not running.

#!/bin/bash

DEV_ORA=$( grep -ic ORA /etc/multipath.conf )

if grep -q -i "release 5" /etc/redhat-release
then
  echo "Red Hat Release 5"
  ls -l /dev/mapper/mpath* | egrep -v "mpath0|p1" | awk '{print $10}'> /tmp/dump.txt
  echo "$DEV_ORA"
elif [ "$DEV_ORA" -eq 0 ]
then
  ls -l /dev/mapper/ORA* | grep -v p1 |awk '{print $10}'>> /tmp/dump.txt
  echo "Found Oracle ASM DISK"

fi

if grep -q -i "release 6" /etc/redhat-release
then
  echo "Red Hat Release 6"
  ls -l /dev/mapper/mpath* | egrep -v "mpath0|mpatha|p1" | awk '{print $9}'> /tmp/dump.txt

elif [ "$DEV_ORA" -eq 0 ]
then
  ls -l /dev/mapper/ORA*|grep -v p1 |awk '{print $9}'>> /tmp/dump.txt
  echo "Found Oracle ASM DISK"
else
  echo "Running neither RHEL6.x nor RHEL 5.x !"
fi

Then I run the script using debug and here is the output.

++ grep -ic ORA /etc/multipath.conf
+ DEV_ORA=58
+ grep -q -i 'release 5' /etc/redhat-release
+ '[' 58 -eq 0 ']'
+ grep -q -i 'release 6' /etc/redhat-release
+ echo 'Red Hat Release 6'
Red Hat Release 6
+ egrep -v 'mpath0|mpatha|p1'
+ awk '{print $9}'
+ ls -l /dev/mapper/mpatha /dev/mapper/mpathap1 /dev/mapper/mpathap2 /dev/mapper/mpathb /dev/mapper/mpathbp1 /dev/mapper/mpathc /dev/mapper/mpathcp1 /dev/mapper/mpathd /dev/mapper/mpathdp1

For some reason this line.
ls -l /dev/mapper/ORA* | grep -v p1 |awk '{print $10}'>> /tmp/dump.txt
It never execute at all.

Thank you

Thanks,

I was able to fix it my self.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.