Unix Shell - How come this loop doesn't work?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > September 2007 > How come this loop doesn't work?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How come this loop doesn't work?
Chad

2007-09-21, 1:27 pm

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

Ed Morton

2007-09-21, 1:27 pm

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.
Ed Morton

2007-09-21, 1:27 pm

Ed Morton wrote:

> Chad wrote:
>
>
>
> 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.

loki harfagr

2007-09-21, 1:27 pm

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

> Chad wrote:
>
> 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.

Chad

2007-09-22, 7:16 pm

On Sep 21, 8:37 am, loki harfagr <l...@DarkDesign.free.fr> wrote:[vbcol=seagreen]
> On Fri, 21 Sep 2007 08:21:10 -0500, Ed Morton wrote:
>
>
>
>
>
>
> 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!?
>
>
>


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

Chad

Bill Marcum

2007-09-22, 7:16 pm

On Sat, 22 Sep 2007 13:48:38 -0700, Chad
<cdalten@gmail.com> wrote:
>
>
> On Sep 21, 8:37 am, loki harfagr <l...@DarkDesign.free.fr> wrote:
>
>
> 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.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com