Tail -f

Tail -f

Post by John Mans » Wed, 06 Feb 2002 02:16:03



Is there a clean way to exit tail -f <file> running within a shell
script and stay  within the script? ctl-c stops tail but also exits
the script. Dazed & Confused.
 
 
 

Tail -f

Post by Ben Altma » Wed, 06 Feb 2002 02:29:11



> Is there a clean way to exit tail -f <file> running within a shell
> script and stay  within the script? ctl-c stops tail but also exits
> the script. Dazed & Confused.

You could trap ctrl-c that would kill the tail and continue in your
script.
    trap "kill \$!" INT
    tail -f file &
    wait
    trap - INT

regards,
Ben

 
 
 

Tail -f

Post by Larry Sta » Wed, 06 Feb 2002 02:51:27



Quote:>Is there a clean way to exit tail -f <file> running within a shell
>script and stay  within the script? ctl-c stops tail but also exits
>the script. Dazed & Confused.

You didn't mention which shell you are using, or on what condition's you
wish to exit the "tail -f".

If you with to let the tail run for some pre-determined amount of time
you might try:
        tail -f <file> &
        sleep <seconds>
        kill -2 %1
or an equivalent that works with your shell.
If you wish to terminate it on command, perhaps:
        tail -f <file> &
        read ans
        kill -2 %1
which would wait for any keystroke from the keyboard and then
kill the "tail -f".

Good luck,
--

=============================================================
There are only three sports: bullfighting, motor racing, and
mountaineering; all the rest are merely games. - Ernest Hemingway

 
 
 

1. hairy tail (was Re: tail -f & RAM disk device driver wanted)

-----BEGIN PGP SIGNED MESSAGE-----

Gawain> I have successfully implemented tail -f functionality by
Gawain> detecting file size changes using stat().  If the file size
Gawain> has changed I do whatever I want to do, if it has not changed
Gawain> I just sleep(1).

Gawain> This actually works quite well and is not CPU intensive at all
Gawain> - in fact it seems LESS CPU intensive then whatever "tail -f"
Gawain> is doing!!

Martin> That is all fine and dandy, but you can only read from regular
Martin> files (or maybe pipes as well?) that way. Try to read from a
Martin> character device, and you loose[sic]. (I think that this can make
Martin> quite a lot of sense at times.)

Well the solution is a "hairy" tail (hmm ;-) which checks whether it
is an ordinary file or a device at the start, and has a read-loop of
each type.

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2i
Comment: Processed by Mailcrypt 3.4, an Emacs/PGP interface

iQB1AwUBMUbAmedsuUurvcRtAQE6gwMAv+wD6OKTUi3eJjeBqaUxIC/s088z0YDX
Urcbt86L5aRqgmPz8PUqU+59kVkQgEIKp9MI3NzavrgsIF5iX2o0t8R2snpu4G4E
G9roeaMW8u6T03yi+46DdeNEvw62FUq4
=hZjq
-----END PGP SIGNATURE-----
--

APM Ltd., Poseidon House, Castle Park, Cambridge CB3 0RD

2. S3-868 Animation support ?

3. non-static buffer tail (was Re: `tail' limitation)

4. Q: who fingered my unix account?

5. "tail" stops tailing?

6. Listmaster request: Blacklist rms@gnu.org

7. head -100 foo | tail -20

8. Compiling a new kernel? How?

9. script reading 'tail -f file' output

10. Do command when tail -f some_file | grep some_exp, matches?

11. `tail' limitation

12. RMS: The tail waggeth the dog

13. Q: Sendmail Bug using From: |/bin/tail|/bin/sh