[ale] Terminals within a terminal

john_galt at usa.com john_galt at usa.com
Fri Nov 14 11:19:43 EST 2003


> Message: 2
> Date: Thu, 13 Nov 2003 15:55:05 -0500 (EST)
> From: "John Wells" <jb at devsea.com>
> Subject: Re: [ale] Terminals within a terminal
> To: "Atlanta Linux Enthusiasts" <ale at ale.org>
> Cc: "Atlanta Linux Enthusiasts" <ale at ale.org>
> Message-ID: <57547.66.192.236.118.1068756905.squirrel at mail.devsea.com>
> Content-Type: text/plain;charset=iso-8859-1
> 
> Dow,
> 
> I'm not, however, after a tabbed view.  More of a "see 6 logs at once"
> view...
> 
> Thanks!
> John
> 
> Dow Hurst said:
> 
>>Konsole gives multiple shells in one window and the Gnome Terminal does
>>it too.
>>Dow
> 
> 
I just use multiple tail -f commands in a single window. Often, I'll 
pipe the output from tail into a simple awk command. So if I want to 
watch the sendmail log and the web server log on one server, I'll run a 
quickie script like this:

-----
#!/bin/sh
tail -f /var/log/maillog|awk '{print "MAIL: "$0}'&
tail -f /var/www/logs/access_log|awk '{print " WWW: "$0}'&
top i b|bannertop&
-----

That last line runs top through another awk script that saves the cursor 
position, moves the cursor to 0,0, prints the top block, then restores 
the cursor postition. The script is a little involved, but here's the 
actual script:

--- bannertop ---
#! /bin/awk -f
BEGIN { "tput cup 0 0" | getline term_home      # Home cursor (pos 0,0)
         close ("tput cup 0 0")
         "tput sc" | getline term_sc             # Save cursor position
         close ("tput sc")
         "tput el" | getline term_clreol         # Clear to end of line
         close ("tput el")
         "tput rc" | getline term_rc             # Restore cursor postion
         close ("tput rc")
         "tput lines" | getline term_lines       # Number of lines on 
terminal
         close ("tput lines")
         for (i=7;i<term_lines;i++) {
                 cmd = "tput csr " (i+1) " " term_lines
                 cmd | getline term_setscroll[i] # Set scrolling region
                 close (cmd)
         }
}

/load average/ {
         if (bannertext) {
                 print term_sc term_home bannertext term_clreol 
term_setscroll[bannerlines++]
                 while (bannerlines < lastbannerlines) {
                         print term_clreol
                         lastbannerlines--
                 }
                 lastbannerlines=bannerlines
                 printf "%s",term_rc
         }
         bannertext=""
         bannerlines=0
         fflush ("")
}

!/^$/ {
         bannertext = bannertext term_clreol $0 "\n"
         bannerlines++
}
------

Sorry if the lines wrapped a bit funny there. With a little work, you 
should be able to make it function.

One of these days, I plan to get into the source code on top and make it 
put a trailer line of some kind out that I can key the awk script on 
(instead of 'load average') so that the screen isn't always 1 cycle 
behind, but that's pretty low priority for me.

Also, on some of my servers, I sometimes comment out the entry for 
mingetty on /dev/tty1 in the /etc/inittab file and put those tail -f and 
top ...|bannertop lines in rc.local with standard out routed to 
/dev/tty1 so that a screen hooked to the server will show these entries. 
I do that on servers that usually have no keyboard, so that you can see 
something on the monitor if you are having problems, or just want to 
keep an eye on the server.

Finally, if you want the top _n_ lines of the screen to always be the 
last _n_ entries in a certain log (say /var/log/speciallog for example), 
you could write an awk script similar to my bannertop to put those lines 
at the top of the screen. Just have your main awk block do getlines from 
"tail -n _n_ /var/log/speciallog" where _n_ is the number of lines you 
want to keep at the top of the screen. Read _n_ lines into a variable 
like "tail_text" and "print term_sc term_home tail_text term_rc" all at 
once when you have all the lines in tail_text.



More information about the Ale mailing list