PDA

View Full Version : Cancel a commad in a script



b-boy
December 11th, 2008, 07:19 AM
Hi

Is there a way to Cancel a command in a running script without ending the script itself?

tdrusk
December 11th, 2008, 07:36 AM
Hi

Is there a way to Cancel a command in a running script without ending the script itself?
I am not very experienced in scripting, but you could ask a question before you execute that part, then throw in an if statement for that command.

davidbilla
December 11th, 2008, 07:42 AM
Is there a way to Cancel a command in a running script without ending the script itself?


If the command is already running, you can check for the process id (pid) of the command and kill it.

You can do something like this.


procid=`ps -C <prg-name> -o pid=`
if test -z $procid
then
#Process not running
else
kill -9 $procid

To do that outside the script


$ procid=`ps -C <prg-name> -o pid=`
$ kill -9 $procid

b-boy
December 11th, 2008, 08:16 AM
I am not very experienced in scripting, but you could ask a question before you execute that part, then throw in an if statement for that command.

I dont think that will work

let me give more info

my script has a for loop with once command inside so when the command is executed ok it goes to the next one but if there is a problem it just hangs as it is waiting for a response no when this happens i just want to cancel this command and let the loop go to the next command

dwhitney67
December 11th, 2008, 11:19 AM
If you have a script that hangs, then perhaps you should focus your attention on that script so that your second script would not need a workaround.

The suggestion offered by davidbilla would work, however it does not solve the root of the problem that you are having.

Also, using a '.' to terminate a sentence is golden. You should consider using it sometimes!

b-boy
December 12th, 2008, 06:55 AM
If you have a script that hangs, then perhaps you should focus your attention on that script so that your second script would not need a workaround.

The suggestion offered by davidbilla would work, however it does not solve the root of the problem that you are having.

Also, using a '.' to terminate a sentence is golden. You should consider using it sometimes!

ok i will try