Link to home
Start Free TrialLog in
Avatar of NuttySquirrel
NuttySquirrel

asked on

calling a script from within another script with timeout?

Hi,

My big goal is:  to write an shell script that would detect hung NFS mount.
My approach:  from within my main program, call a sub program that reads/write from/to directories on the nfs mount. If the sub program doesn't come back after a certain amount of time, kill the sub program and proceed with assumption that the mount is hung.

My question: I dont know linux shell scripting very well, could someone help me with this: specifically, how to call the sub-program with that timeout option? (assuming that nfs mount directory is known)

Env: bash shell.

Thank you.
Avatar of GlobaLevel
GlobaLevel
Flag of United States of America image

did you ping the server..could be donw..
restart the nfs server processes
Avatar of NuttySquirrel
NuttySquirrel

ASKER

Thank you. I'll try the stackoverflow solution.

No I did not try pinging the server. I may add that step into my process. I didn't think pinging the server could replace the step of actually read/write from/to nfs mount in detecting stale one. Please correct me if I'm wrong.

I dont need to do anything to bring the mount back up. Just need to identify stale mount when it occurs.

Will go try out the mentioned solution now.

Thanks.
my terminal does not understand "timeout" command, complaining "command not found" when i try it out.

hmmm....
Sounds like the nfs server is down..did you reboot? Try a mount command
I dont think the nfs server was down. We just dont have timeout command for some reason. Is there any other way?
Can you check out this link and get back to me if it doesnt help;
http://www.cyberciti.biz/tips/nfs-stale-file-handle-error-and-solution.html
uhm, I dont have a stale nfs mount and my script isn't supposed to remount anything if it WERE stale.

I can do directories list and read from my nfs mount directories just fine.
My big goal is:  to write an shell script that would detect hung NFS mount
>> Okay I might be a bit lost ...isnt this waht you want?
I'm starting to think that timeout is not a common command but a user written utility, because i cant find more info about it anywhere .
Yes i need to detect when a mount is stale. So when it's not stale dont do anything. when it is stale, send an alert.

But i can't just have the main programing checking on hung mounts, because if the mount is hung, my program will be hung with it and never comes back, which defeat the purpose of testing. I need my main program to call on another program to test. after a given amount of time if the sub program doesn't come back it will be presumed as hung, and the main program can send an alert. Key point is to have 2 processes here: one for driving the flow, one is to do the testing. and I'm trying to figure out how to say it in shell script "sub program go do your testing, if in 5 sec, you're not back, main program is moving on"
thats a little tougher...

check your settings in /etc/fstab of course and make sure you are set up right in there...here is a tuning section for mounting nfs if that will help...

http://nfs.sourceforge.net/nfs-howto/ar01s04.html#mounting_remote_dirs
I do check that file, but it doesn't reflect hung mount. hence the need for this script i'm trying to implement.

it is more a shell scripting solution i'm looking for than a NFS related issue. Forget the NFS mount. There has got to be a way to orchestrate 2 processes like i described. I just dont know it.
ASKER CERTIFIED SOLUTION
Avatar of NuttySquirrel
NuttySquirrel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I talked to different co-worker  and saw a few suggestion on the internet. The key point is
-  to run the sub process in the background
- have the main process sleep
- check on the existence/content of this pid file for various information depending on specific implementation from the main process after the sleep?wait period.