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.
Shell ScriptingLinux OS Dev

Avatar of undefined
Last Comment
NuttySquirrel

8/22/2022 - Mon
GlobaLevel

GlobaLevel

did you ping the server..could be donw..
GlobaLevel

restart the nfs server processes
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
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.
NuttySquirrel

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

hmmm....
GlobaLevel

Sounds like the nfs server is down..did you reboot? Try a mount command
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
NuttySquirrel

ASKER
I dont think the nfs server was down. We just dont have timeout command for some reason. Is there any other way?
GlobaLevel

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
NuttySquirrel

ASKER
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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
GlobaLevel

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?
NuttySquirrel

ASKER
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 .
NuttySquirrel

ASKER
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"
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
GlobaLevel

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
NuttySquirrel

ASKER
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
NuttySquirrel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
NuttySquirrel

ASKER
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.
Your help has saved me hundreds of hours of internet surfing.
fblack61