Re: Controlled exit from 'tail -f' within a shell script

From: Needham, Lon (Lon.Needham@AMERICREDIT.COM)
Date: Tue Jun 25 2002 - 09:18:37 EDT


try this. I believe I got this out the AIX Ver.4 Kornshell Programming book.
trap 'echo "\n* INTERRUPT *\n"' 2 3 # trap user in shell

-----Original Message-----
From: Robert Bardos [mailto:Robert.Bardos@ZUGERKB.CH]
Sent: Tuesday, June 25, 2002 6:44 AM
To: aix-l@Princeton.EDU
Subject: Controlled exit from 'tail -f' within a shell script

Hi all,

I am new to this list (and new to AIX, new to shell scripts ....) so please
bear with me.
My intention is to provide our operators with a simple, telnet based tool
that allows them to start/stop some subsystems and to watch these
subsystems' logs continuously. And: as an exercise for myself I want to do
it all with shell scripts.

So basically the logic is:

  do while true
      echo selection screen
      read user_selection
      case "$user_selection" in
           x) tail -f my_log_file
           .....
      esac
      ....
  done

According to the man(ual) and some tests 'tail -f' can only be ended by
pressing ctrl-c.
This also cancels my shell script which is not the desired effect. (I
experimented with the trap command but to no avail). Any idea how I can
limit ctrl-c to just the 'tail -f' command?

Should there be a more appropriate list for this kind of question then
please advise.

Thanks in advance
Robert



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:00 EDT