Run/wait command in linux

(imported topic written by cstoneba)

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?

(imported comment written by BrianPGreen)

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.

(imported comment written by cstoneba)

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”}”

(imported comment written by Rafael Rodriguez)

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”}”