Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NFS Script....help

Status
Not open for further replies.

icu812

MIS
Sep 10, 2001
52
US
Been working on a script for several hours now. Am trying to NFS mount some filesystems coming off of several different hosts to a box after it is rebooted. Here is what my script looks like:
#!/bin/ksh
#
for SERVER in `cat /bin/danka/nfs.lis|cut -f 1 -d :`
do
for MP in `cat /bin/danka/nfs.lis|cut -f 3 -d :`
do
for FS in `cat /bin/danka/nfs.lis|cut -f 2 -d :`
do
if ! ping -c 5 ${SERVER} 1>/dev/null 2>/dev/null
then
clear
echo "\n\n\n"
echo "Server: ${SERVER} is not available......\n"
echo "Contact UNIX Support.....\n\n\n"
exit
fi
if mount |grep -q -w ${MP}
then
clear
echo "\n\n\n"
echo "The $MP mount point is already mounted......\n"
echo "Contact UNIX Support.....\n\n\n"
exit
fi
if mount $SERVER:$FS $MP
then
clear
echo "\n\n\n"
echo "The $FS mount point has been mounted.......\n"
fi
done
done
done
***********************************************************
the nfs.lis file that it searches has several entries in it that look like this:
host:filesystem:mountpoint
host:filesystem:mountpoint
host:filesystem:mountpoint
************************************************************
when I run this job, the first NFS filesystem is mounted, I then get a message that states the other NFS filesystems are already mounted(but they are not of course). Can someone please lend their expertise to this problem. Your help would be greatly appreciated. Thanks






 
The way this is coded, if you have only 3 filesystems mounted, the inner loop will run 27 times, the middle one 9 times, and the outer one 3 times. Nested loops (in this case a "do within a do within a do" are probably not what you want.

for line in `cat file.lis` ; do
host=`echo "$line"|cut -f1 -d:`
FS=`echo "$line"|cut -f2 -d:`
MP=`echo "$line"|cut -f3 -d:`
...
... Do your processing
...
done

This way, the data in the file is only procesed once.

Bill.
 
Thank you, Thank you, Thank you. Your suggestion saved the day(not to mention my sanity). Can you please answer one more question??? In one portion of my script I check to make sure that the mount point that it is going to attempt to mount isn't already mounted.(if mount |grep -q -w ${MP}) I don't have it quite right because when it finds a mount point that is already mounted, it stops and doesn't mount anything else after that. Any suggestions??????? Thanks again. Here is a sample of what my script now looks like:

#!/bin/ksh
#
for line in `cat /tmp/nfs.lis`
do
SERVER=`echo "$line"|cut -f 1 -d :`
FS=`echo "$line"|cut -f 2 -d :`
MP=`echo "$line"|cut -f 3 -d :`
if ! ping -c 5 ${SERVER} 1>/dev/null 2>/dev/null
then
clear
echo "\n\n\n"
echo "Server: ${SERVER} is not available......\n"
echo "Contact UNIX Support.....\n\n\n"
exit
fi
if mount |grep -q -w ${MP}
then
clear
echo "\n\n\n"
echo "The $MP mount point is already mounted......\n"
echo "Contact UNIX Support.....\n\n\n"
exit
fi
if mount -o timeo=12 -o proto=tcp ${SERVER}:$FS $MP
then
clear
echo "\n\n\n"
echo "The $MP mount point has been mounted.......\n"
fi
done
 
The "exit" statement is the cause of that. The "exit" command exits the script. You probably don't want to do that.

Bill.
 
When I took the "exit" statements out the script does not do what it's suppossed to. Even though the NFS mounts are mounted, it tells me that it is mounting them instead of telling me that they are already mounted. thanks
 
I was able to "clean the script up" by adding a few if then else statements. Thanks for all your help!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top