?
Solved

open two xterm windows and keeping them open to viewl tail'd logs

Posted on 2007-10-08
4
Medium Priority
?
1,001 Views
Last Modified: 2012-05-05
HI,
I'm running SUSE linux and I would like a script to run these two commands in two separate terminal windows.

tail -f /data/op_log_file

tail -f /data/dev_log_file

thanks,
0
Comment
Question by:zaphs
  • 2
4 Comments
 
LVL 8

Expert Comment

by:Bradley Haynes
ID: 20037674
Just use the screen command which in affect open multiple terminals in the same session. I use this with SSH to remote in and run several jobs at once.
0
 
LVL 8

Expert Comment

by:Bradley Haynes
ID: 20037719
The secret is to use the screen command. And I will tell you all the commands you need in order to make it work wonders for you. But first a little copy and paste from the screen website: (LINK)

Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells. Each virtual terminal provides the functions of the DEC VT100 terminal and, in addition, several control functions from the ANSI X3.64 (ISO 6429) and ISO 2022 standards (e.g., insert/delete line and support for multiple character sets). There is a scroll back history buffer for each virtual terminal and a copy-and-paste mechanism that allows the user to move text regions between windows. When screen is called, it creates a single window with a shell in it (or the specified command) and then gets out of your way so that you can use the program as you normally would. Then, at any time, you can create new (full-screen) windows with other programs in them (including more shells), kill the current window, view a list of the active windows, turn output logging on and off, copy text between windows, view the scroll back history, switch between windows, etc. All windows run their programs completely independent of each other. Programs continue to run when their window is currently not visible and even when the whole screen session is detached from the users terminal.

From the description above you will notice that there are some other advantages to using screen besides the ability to split screen your console. For instance, if you are using putty on a somewhat unstable internet connection and your connection is lost you will lose your console session and any program instance that is running. But if you are using screen your terminal instance will continue to run even if you lose your connection and all you have to do is reconnect and reattach to your screen session.

If you do not have screen, you can obtain it at the link listed above or from your Linux distros update command such as yum or apt-get.

I will now give you the commands you require to use screen efficiently. Any command when you are inside screen begins with CNTL-A.

To start you will have to call the first instance of screen. You can combine a lot of these commands into one command line argument but I prefer to show you one command at a time. Run the following command:

    screen

You will now see the shell prompt again. To split screen hit the following key combinations:

    CNTL-A

    SHIFT-S

You will now need a second screen instance to run in the bottom window. Run the screen command again:

    screen

Run a command such as man, htop, or top. You will notice that it fills the top half of the screen.

You will now have to toggle to the bottom screen by hitting the following key combinations:

    CNTL-A

    TAB

You will now be in the bottom window, although you will not see your command prompt yet. You will have to toggle through the instances of screen in the bottom window to get to it. Use the following key combinations to do this:

    CNTL-A

    N

or:

    CNTL-A

    P

The N stands for next and the P stands for previous. It just allows you to step forward and backward through as many instances of screen that you have running. If you see the same output in both windows just do the same key combo again to get to the next version of screen.

Once you get the shell prompt in the bottom screen you can run your second command and view the output from both running instances. You can now view a man page in the top window and craft your command below or view htop and iftop in the same window at the same time. You can also split the screen more times but I wouldnt recommend it unless you have some decent resolution set for your text console which can be controlled in your boot options in grub or lilo but that is another lesson.

You may find a few more commands useful during your stay with screen. You may with to leave the current session running in the background and jump back to you regular console. You can do that by detaching which is done with the following key combo:

    CNTL-A

    D

Now that you are detached, which is what also happens during loss of connectivity, you may want to reattach to one of your screen instances. You will first need to list the instances of screen by typing the following command:

    screen -list

You will the get a list similar to:

    There is a screen on:
    3880.pts-0.localhost (Detached)

To reattach to the instance listed above, type:

    screen -r 3880.pts-0.localhost

The part after -r will change depending on your linux box.

You will notice that you are now back into your detached session of screen.

Now that you know the basics of screen, I am sure you will become accelerated at learning other Linux commands. Take care, and enjoy the ease of use!
0
 
LVL 9

Expert Comment

by:sanjooz
ID: 20038658
In Gnome, you could something like this

gnome-terminal -e "tail -f /data/op_log_file"
gnome-terminal -e "tail -f /data/dev_log_file"
0
 
LVL 3

Accepted Solution

by:
4dimach earned 2000 total points
ID: 20111343
Create a script:

#!/bin/bash
xterm -e tail -f /var/log/messages &
xterm -e tail -f /var/log/dmesg &
exit 0

Make it executable with chmod +x.
You can run it when you need it or put the script in ~/.kde/Autostart/ folder.

If you like to have different fonts and colors in xterm, man xterm.

Hope it helps.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month16 days, 22 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question