0

I am trying to mount as below, where the mount point is version dependant:

1) Find if any of the below 2 are mounted.

2) Find RHEL version, then mount one of the below

  • mount -o soft 123.45.678.9:/web /mnt3 (RHEL 5)
  • mount -o vers=3 123.45.678.9:/web /mnt3 (RHEL 6)

3) If fails out put statement.

Tried these 2 codes

1st

mount > /tmp/mountlog;
if grep -ohw "soft,addr=123.45.678.9" /tmp/mountlog; then echo -e " RHEL 5 MOUNT \e[1;33mALREADY\e[00m AVAILABLE \e[1;33m-PASSED\e[00m ";
elif grep -ohw "nfsvers=3,addr=123.45.678.9" /tmp/mountlog; then echo -e " RHEL 6 MOUNT \e[1;33mALREADY\e[00m AVAILABLE \e[1;33m-PASSED\e[00m ";
elif grep -ohw "5.*" /tmp/red; mount -o soft 123.45.678.9:/web /mnt3 &>/dev/null; then mount > /tmp/mountlog; fi
if grep -ohw "soft,addr=123.45.678.9" /tmp/mountlog; then echo -e " RHEL 5 MOUNT AVAILABLE \e[1;33m-PASSED\e[00m ";
elif grep -ohw "6.*" /tmp/red; mount -o vers=3 123.45.678.9:/web /mnt3 &>/dev/null; then mount > /tmp/mountlog; 
if grep -ohw "nfsvers=3,addr=123.45.678.9" /tmp/mountlog; then echo -e " RHEL 6 MOUNT AVAILABLE \e[1;33m-PASSED\e[00m ";
else echo -e " MOUNT DEVICE NOT AVAILABLE Or NOT VALID RHEL VERSION 5 or 6. \e[00;31mFAILED\e[00m "; fi; fi | tee -a /tmp/log;

2nd

mount > /tmp/mountlog;
if grep -ohw "soft,addr=123.45.678.9" /tmp/mountlog; then echo -e " RHEL 5 MOUNT \e[1;33mALREADY\e[00m AVAILABLE \e[1;33m-PASSED\e[00m ";
elif grep -ohw "nfsvers=3,addr=123.45.678.9" /tmp/mountlog; then echo -e " RHEL 6 MOUNT \e[1;33mALREADY\e[00m AVAILABLE \e[1;33m-PASSED\e[00m ";
elif grep -ohw "5.*" /tmp/red; mount -o soft 123.45.678.9:/web /mnt3 &>/dev/null; then mount > /tmp/mountlog; fi
if grep -ohw "soft,addr=123.45.678.9" /tmp/mountlog; then echo -e " RHEL 5 MOUNT AVAILABLE \e[1;33m-PASSED\e[00m ";
elif grep -ohw "6.*" /tmp/red; mount -o vers=3 123.45.678.9:/web /mnt3 &>/dev/null; then mount > /tmp/mountlog; fi
if grep -ohw "nfsvers=3,addr=123.45.678.9" /tmp/mountlog; then echo -e " RHEL 6 MOUNT AVAILABLE \e[1;33m-PASSED\e[00m ";
else echo -e " MOUNT DEVICE NOT AVAILABLE Or NOT VALID RHEL VERSION 5 or 6. \e[00;31mFAILED\e[00m "; fi | tee -a /tmp/log;

1 Answer 1

0

There are a few things wrong with the script; First thing that sticks out if this line:

elif grep -ohw "5.*" /tmp/red;

I see nothing writing to /tmp/red. Also, there is a file called /etc/redhat-release which contains the version;

You're if strucure is a bit off too; if grep -ohw "whatever" will retunr n counts of whatever; this will ammount to if soft,addr=123.45.678.9, which to bash doesnt really make sense! I'd use grep -c , which gives a numerical caount of occurances of string in file;

i.e

mount > /tmp/mountlog;

if [ $(grep -c "soft,addr=123.45.678.9" /tmp/mountlog) -gt 0 ]
        then echo -e " RHEL 5 MOUNT \e[1;33mALREADY\e[00m AVAILABLE \e[1;33m-PASSED\e[00m ";
elif [ $(grep -c  "nfsvers=3,addr=123.45.678.9" /tmp/mountlog) -gt 0 ]
        then echo -e " RHEL 6 MOUNT \e[1;33mALREADY\e[00m AVAILABLE \e[1;33m-PASSED\e[00m ";
elif [ $(grep -c "5.*" /etc/redhat-release) -gt 0 ];
        then mount -o soft 123.45.678.9:/web /mnt3 &>/dev/null;
elif [ $(grep -c "6.*" /etc/redhat-release) -gt 0 ];
        then mount -o vers=3 123.45.678.9:/web /mnt3
fi
mount > /tmp/mountlog;


if [ $(grep -c "soft,addr=123.45.678.9" /tmp/mountlog) -gt 0 ];
        then echo -e " RHEL 5 MOUNT AVAILABLE \e[1;33m-PASSED\e[00m ";
elif [ $( grep -c "nfsvers=3,addr=123.45.678.9" /tmp/mountlog) -gt 0 ];
        then echo -e " RHEL 6 MOUNT AVAILABLE \e[1;33m-PASSED\e[00m ";
else
echo -e " MOUNT DEVICE NOT AVAILABLE Or NOT VALID RHEL VERSION 5 or 6. \e[00;31mFAILED\e[00m ";
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .