sending control c in the loop

I want to go through the list of items and run it.

while running it, some of them will have either

>there is no response # and then end it... so that it can go to next item

OR

>there is response # but in order to break out of it, u need to do Control c.

How do you send control c within loop?

Please help.

thanks.

If you want to come out of loop, use either break or exit

not exit out of the loop.. basic mechanic of the program should be,

for N in a b c d e f g h i j k
do
for X in 1 2 3 4 5 6 7 8
do
output=$(someprogram $X@$N)
if [ $output -eq whatever ] ; then
echo "$X@$N is $output"
else
echo "$X@$N is NOT whatever"
fi
done
done

Problem is, this someprogram that I am running so that it will either spit out
1)whatever OR 2)some other response but in order to quit from that program, you need to do control c

a)where do I put control c statement in the script
b)and more importantly, HOW do I send control c from shell script..

I dont understand by what you mean by quitting from the script. But you can send an interrupt signal by

kill -2 pid

Check

kill -l 

for all signals.
I am still not clear of your requirement. Sorry about that. :confused:

output=$(someprogram $X@$N)

when above is ran,

above program will spit out either of below outputs

Connected to someprocess@host3
>type message
> <--- since we are just seeing whether we can connect to this process, we will quit this bye
doing control C

OR

Cannot connect: connection refused

OR maybe I am just doing a wrong thing with shell script.. maybe I need to run Expect??

Please advise.

How would you know when to send the ctrl-c (SIGINT) to the child process?

How does the child process (the one you are want to kill) normally quit?

Once again,

Connected to someprocess@host3
>type message
> <--- since we are just seeing whether we can connect to this process, we will quit this bye
doing control C

OR

Cannot connect: connection refused

If I was doing this interactively,

I would type

./program process.1@host13

IF process.1 was doing what's it suppose to be doing, i would see

Connected to someprocess@host3
>type message
>

and I can type command and do stuff... and only way to quit out of that is to do control-C
But if you do get above message it means from my host to that process on host3, I am able to communicate and that's what I am trying to find out

If process.1 was not up, than I would see

Cannot connect: connection refused

and it will give me back the prompts.

Please let me know if needs more info..
I am just not sure if sending control c within loop is possible in the script or not