Find the answer to your Linux question:
Results 1 to 6 of 6
I have a shell script which issue a command provided by a 3rd party software to check its status. My script will hang if the 3rd party software is hung ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2007
    Posts
    19

    Is there a way to prevent my script from hanging ?


    I have a shell script which issue a command provided by a 3rd party software to check its status. My script will hang if the 3rd party software is hung or loop because the command will never return anything. Is there a way to prevent my script from hanging ? Can I use a timer to say I'll wait for x number of seconds and break.
    If this 3rd party software is hung, the display status command provided by them will sit there and return nothing. Even a control C is not able to break out of it. So I cannot put a control C in my script.

  2. #2
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    925
    Your script isn't hung your 3rd party software is the problem its not handling some condition gracefully. Does the other software react the same when not run from within a script? Have you tried running your other program in the background in the script adding &. If that line is going into the background the script will continue on. If you want to get fancy you could find the PID of the other program then check to see if its still runing.

    But I would be trying to find out why the other software is getting hung, because throwing in the background you could end up with a bunch of zombie processes.
    A lion does not lose sleep, over the opinion of sheep.

  3. #3
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,378
    docbop is right, the goal is to get this 3rd_party software fixed.
    Everything else is just a workaround.

    However, to mitigate the situation you could use the timeout command
    Code:
    man timeout
    You must always face the curtain with a bow.

  4. #4
    Just Joined!
    Join Date
    May 2007
    Posts
    19
    Quote Originally Posted by Irithori View Post
    docbop is right, the goal is to get this 3rd_party software fixed.
    Everything else is just a workaround.

    However, to mitigate the situation you could use the timeout command
    Code:
    man timeout
    Thanks, I'll tried the time out command. We paid for the 3rd party software long time ago and it is difficult to get something fixed with a small software company.

  5. #5
    Just Joined!
    Join Date
    May 2007
    Posts
    19
    I am running Opensuse 11

    Linux myhost218 2.6.32.45-0.3-default #1 SMP 2011-08-22 10:12:58 +0200 x86_64 x86_64 x86_64 GNU/Linux

    But timeout is not there
    If 'timeout' is not a typo you can run the following command to lookup the package that contains the binary:
    command-not-found timeout
    -bash: timeout: command not found

    Is this a separate rpm that I need to install ?

  6. #6
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,498
    Run
    Code:
    command-not-found timeout
    and it should tell you what package to install
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    The Fifth Continent

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •