Topic
  • 3 replies
  • Latest Post - ‏2013-06-04T07:40:07Z by Rafael Rodriguez
cstoneba
cstoneba
286 Posts

Pinned topic run/wait command in linux

‏2013-05-30T16:15:44Z |

i'm trying to issue a command (wait sh -c "yum distribution-synchronization -y") via a linux bigfix action script, however i have 2 problems.

1) if the exit code of the command !=0, i want to set an client setting. This works now because "wait" waits until the yum command completes an returns the exit code

2) if yum is running for 60minutes, terminate the process.. This is a problem because 'wait' will wait until yum completes, so I can monitor the time it is running to terminate it.  If i use 'run' instead of 'wait', it doesn't appear to return an action exit code (probably because it issues the yum command and moves on).

Can anyone help with a workaround?

  • BrianPGreen
    BrianPGreen
    66 Posts
    ACCEPTED ANSWER

    Re: run/wait command in linux

    ‏2013-05-31T00:18:38Z  

    I'm not sure how helpful this is, but I think you'll have to still use the "wait" command from actionscript, and then wait on a shell script that does the timeout and kill of the yum command.  I'm not a shell ninja though, so I'm not exactly sure how to do that from sh.

  • BrianPGreen
    BrianPGreen
    66 Posts

    Re: run/wait command in linux

    ‏2013-05-31T00:18:38Z  

    I'm not sure how helpful this is, but I think you'll have to still use the "wait" command from actionscript, and then wait on a shell script that does the timeout and kill of the yum command.  I'm not a shell ninja though, so I'm not exactly sure how to do that from sh.

  • cstoneba
    cstoneba
    286 Posts

    Re: run/wait command in linux

    ‏2013-05-31T16:56:13Z  

    I'm not sure how helpful this is, but I think you'll have to still use the "wait" command from actionscript, and then wait on a shell script that does the timeout and kill of the yum command.  I'm not a shell ninja though, so I'm not exactly sure how to do that from sh.

    I got it to work this way:

     

    delete "{(client folder of current site as string) & "/__appendfile"}" 
    appendfile #!/bin/sh 
    appendfile (your script/command goes here) & pid=$! 
    appendfile (sleep number of seconds to wait && kill $pid 2> /dev/null) & waiter=$! 
    appendfile wait $pid 2> /dev/null 
    appendfile mainrc=$? 
    appendfile kill $waiter 2> /dev/null 
    appendfile waitrc=$? 
    appendfile exit $mainrc 
    wait chmod 555 "{(client folder of current site as string) & "/__appendfile"}" 
    wait sh "{(client folder of current site as string) & "/__appendfile"}" 
     
  • Rafael Rodriguez
    Rafael Rodriguez
    4 Posts

    Re: run/wait command in linux

    ‏2013-06-04T07:40:07Z  

    I would create a log of distribution. In each line would put in execution, and so by an analysis would control the execution.

     

    delete "{(client folder of current site as string) & "/__appendfile"}" 
    appendfile #!/bin/sh 
    appendfile (your script/command goes here) & pid=$! 
    appendfile (sleep number of seconds to wait && kill $pid 2> /dev/null) & waiter=$! 
    appendfile wait $pid 2> /dev/null 

    appendfile echo $pid2 >> /var/log/file_logs.log

    appendfile mainrc=$? 
    appendfile kill $waiter 2> /dev/null 
    appendfile waitrc=$? 

    appendfile echo $? >> /var/log/file_logs.log

    appendfile exit $mainrc 
    wait chmod 555 "{(client folder of current site as string) & "/__appendfile"}" 
    wait sh "{(client folder of current site as string) & "/__appendfile"}"