LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-28-2003, 09:02 AM   #1
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Rep: Reputation: 15
bash scripting: how to tell when an nfs connection...


... can't be made.

I'm writing a bash script that will run on computer a and open an nfs connection between computer a and computer b. Then it's going to copy some files accross and close the connection. I have it working, just a slight problem - if a connection to computer b can't be made (say for example because it's switched off) then the files just get copied to the directory where the nfs filesystem would have been.

Is there some easy what to tell when this has happened? At the moment I'm trying to print the output of the the mount statement to a variable and then read that variable to decide what to do next. I'm having trouble with this (probably because my code is all wrong)

MOUNTERROR=/root/backup-keeper/errorlog.txt

mount -t nfs 192.168.0.63:/mnt/FARMER-mirror/ /mnt/keeper/ > MOUNTERROR
if [ MOUNTERROR= "mount: RPC: Remote system error - No route to host" ] then
exit
fi

I turned off computer b to test this, but when I look in errorlog.txt there's nothing in there. Oh and bash doesn't seem to think much of everything after then.

Can anybody help me out? There's probably a way better way to tackle this isn't there?

Cheers,

~James~
 
Old 10-28-2003, 01:23 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I think that you are trying is:
Code:
MOUNTERROR=/root/backup-keeper/errorlog.txt
mount -t nfs 192.168.0.63:/mnt/FARMER-mirror/ /mnt/keeper/ > $MOUNTERROR
if [ `cat $MOUNTERROR` -eq "mount: RPC: Remote system error - No route to host" ]; then
echo FAILED
fi
There are a few problems:
It may give the error on stderr
It may fail for another reason

Solution - look at the return code and only continue if it passed - ie:
Code:
mount -t nfs 192.168.0.63:/mnt/FARMER-mirror/ /mnt/keeper/
if [ $? -eq 0 ]; then
echo Mount OK
fi
 
Old 10-28-2003, 01:53 PM   #3
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Original Poster
Rep: Reputation: 15
Thanks! I've made the changes, but will wait until tomorrow to test it cos I'm not near computer a or b until then!

~James~
 
Old 10-29-2003, 03:23 AM   #4
jimieee
Member
 
Registered: Aug 2003
Location: London, UK
Distribution: Debian and Fedora for play and RHEL + Solaris for work
Posts: 172

Original Poster
Rep: Reputation: 15
Ok First of all thanks for that, it seems to work a lot better than my first dismal attempt. Second, how do I tell it to actually stop processing the script? Third, how do I go telling if any error message has come up. I think the best way to tackle that one is to have something a long the line of "....if not null..." seeing as the mount command gives no feedback if the mount is successful....

Thanks for this!

~James~
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting pete1234 Programming 1 09-27-2005 01:48 AM
bash scripting fnoyan Programming 1 01-18-2005 07:35 AM
BASH Scripting ? eroica Programming 3 06-07-2004 07:51 PM
bash scripting -=MaGo=- Programming 16 08-30-2003 07:07 PM
Bash scripting NSKL Linux - General 2 06-08-2002 12:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration