How come this loop doesn"t work?

How come this loop doesn"t work?

am 21.09.2007 14:39:16 von grocery_stocker

I'm trying to send ctrl-c every three seconds. However, the script
doesnt work. It will just make the initial talk request and then stop
for 10 seconds and make the talk request again. Here is what I did.

#!/bin/bash

while true; do
talk mcnully
kill -INT $!
sleep 3
done


What did I do wrong?

Chad

Re: How come this loop doesn"t work?

am 21.09.2007 15:21:10 von Ed Morton

Chad wrote:
> I'm trying to send ctrl-c every three seconds. However, the script
> doesnt work. It will just make the initial talk request and then stop
> for 10 seconds and make the talk request again. Here is what I did.
>
> #!/bin/bash
>
> while true; do
> talk mcnully
> kill -INT $!
> sleep 3
> done
>
>
> What did I do wrong?

You didn't start "talk" in the background:

talk mcnully &

The "10 seconds" is how long your talk session runs, for whatever reason....

Regards,

Ed.

Re: How come this loop doesn"t work?

am 21.09.2007 15:22:26 von Ed Morton

Ed Morton wrote:

> Chad wrote:
>
>> I'm trying to send ctrl-c every three seconds. However, the script
>> doesnt work. It will just make the initial talk request and then stop
>> for 10 seconds and make the talk request again. Here is what I did.
>>
>> #!/bin/bash
>>
>> while true; do
>> talk mcnully
>> kill -INT $!
>> sleep 3
>> done
>>
>>
>> What did I do wrong?
>
>
> You didn't start "talk" in the background:
>
> talk mcnully &
>
> The "10 seconds" is how long your talk session runs, for whatever

The "10 seconds" is how long your talk session runs (+ 3 seconds of
sleep), for whatever

> reason....
>
> Regards,
>
> Ed.

Re: How come this loop doesn"t work?

am 21.09.2007 17:37:54 von Loki Harfagr

On Fri, 21 Sep 2007 08:21:10 -0500, Ed Morton wrote:

> Chad wrote:
>> I'm trying to send ctrl-c every three seconds. However, the script
>> doesnt work. It will just make the initial talk request and then stop
>> for 10 seconds and make the talk request again. Here is what I did.
>>
>> #!/bin/bash
>>
>> while true; do
>> talk mcnully
>> kill -INT $!
>> sleep 3
>> done
>>
>>
>> What did I do wrong?
>
> You didn't start "talk" in the background:
>
> talk mcnully &

Wouldn't 'talk' need a "real" tty and fail to go backround ?
Afterall, talking is supposed to be an interactive task,
though sometimes some folks are living proofs of the opposite :-)

If the need of the OP for this trick is to check that someone's
back at work on some console I suppose there'd be easier ways
than sending an ink bottle through a closed window and see if it bounces!?

> The "10 seconds" is how long your talk session runs, for whatever
> reason....
>
> Regards,
>
> Ed.

Re: How come this loop doesn"t work?

am 22.09.2007 22:48:38 von grocery_stocker

On Sep 21, 8:37 am, loki harfagr wrote:
> On Fri, 21 Sep 2007 08:21:10 -0500, Ed Morton wrote:
> > Chad wrote:
> >> I'm trying to send ctrl-c every three seconds. However, the script
> >> doesnt work. It will just make the initial talk request and then stop
> >> for 10 seconds and make the talk request again. Here is what I did.
>
> >> #!/bin/bash
>
> >> while true; do
> >> talk mcnully
> >> kill -INT $!
> >> sleep 3
> >> done
>
> >> What did I do wrong?
>
> > You didn't start "talk" in the background:
>
> > talk mcnully &
>
> Wouldn't 'talk' need a "real" tty and fail to go backround ?
> Afterall, talking is supposed to be an interactive task,
> though sometimes some folks are living proofs of the opposite :-)
>
> If the need of the OP for this trick is to check that someone's
> back at work on some console I suppose there'd be easier ways
> than sending an ink bottle through a closed window and see if it bounces!?
>
> > The "10 seconds" is how long your talk session runs, for whatever
> > reason....
>
> > Regards,
>
> > Ed.


How come I have to put 'talk mcnully' as a background job in order for
this code to work?

Chad

Re: How come this loop doesn"t work?

am 23.09.2007 00:04:56 von Bill Marcum

On Sat, 22 Sep 2007 13:48:38 -0700, Chad
wrote:
>
>
> On Sep 21, 8:37 am, loki harfagr wrote:
>> On Fri, 21 Sep 2007 08:21:10 -0500, Ed Morton wrote:
>> > Chad wrote:
>> >> I'm trying to send ctrl-c every three seconds. However, the script
>> >> doesnt work. It will just make the initial talk request and then stop
>> >> for 10 seconds and make the talk request again. Here is what I did.
>>
>> >> #!/bin/bash
>>
>> >> while true; do
>> >> talk mcnully
>> >> kill -INT $!
>> >> sleep 3
>> >> done
>>
>> >> What did I do wrong?
>>
>> > You didn't start "talk" in the background:
>>
>> > talk mcnully &
>>
>> Wouldn't 'talk' need a "real" tty and fail to go backround ?
>> Afterall, talking is supposed to be an interactive task,
>> though sometimes some folks are living proofs of the opposite :-)
>>
>> If the need of the OP for this trick is to check that someone's
>> back at work on some console I suppose there'd be easier ways
>> than sending an ink bottle through a closed window and see if it bounces!?
>>
>> > The "10 seconds" is how long your talk session runs, for whatever
>> > reason....
>>
>> > Regards,
>>
>> > Ed.
>
>
> How come I have to put 'talk mcnully' as a background job in order for
> this code to work?
>
> Chad
>
Otherwise the next command (kill -INT $!) isn't executed until talk has
already died of natural causes.


--
If a subordinate asks you a pertinent question, look at him as if he had
lost his senses. When he looks down, paraphrase the question back at him.