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

Posted on 2007-10-08
Last Modified: 2012-05-05
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

Question by:zaphs
    LVL 8

    Expert Comment

    by:Bradley Haynes
    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.
    LVL 8

    Expert Comment

    by:Bradley Haynes
    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:


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



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


    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:



    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:






    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:



    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!
    LVL 9

    Expert Comment

    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"
    LVL 3

    Accepted Solution

    Create a script:

    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.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
    SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now