We help IT Professionals succeed at work.

calling a script from within another script with timeout?

540 Views
Last Modified: 2012-05-11
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.
Comment
Watch Question

GlobaLevelProgrammer

Commented:
did you ping the server..could be donw..
GlobaLevelProgrammer

Commented:
restart the nfs server processes

Author

Commented:
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.

Author

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

hmmm....
GlobaLevelProgrammer

Commented:
Sounds like the nfs server is down..did you reboot? Try a mount command

Author

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

Commented:
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

Author

Commented:
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.
GlobaLevelProgrammer

Commented:
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?

Author

Commented:
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 .

Author

Commented:
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"
GlobaLevelProgrammer

Commented:
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

Author

Commented:
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.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.