screen-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Logging in screen


From: Thomas Köhler
Subject: Re: Logging in screen
Date: Fri, 14 Dec 2007 07:51:32 +0100
User-agent: Mutt/1.5.4i

Hi,

address@hidden wrote:
> On Thu, Dec 13, 2007 at 10:11:20AM +0000, jan wrote:
> > I am trying to do something that I can't quite get my head
> > around; I hope that somebody with more experience can help
> > me.
> > 
> > This is what I try to do: I have a large number of serial
> > ports attached to one of my linux boxes - I use them as
> > consoles for the other UNIXes, which seems to work fine with
> > minicom. I have set it up so I have a number of screen
> > sessions start up in detached mode, each running a minicom
> > connected to a serial port; this is not complicated, if a
> > little fiddly.

OK, seems fine so far.

> > Minicom runs an initialisation script through 'expect' - the
> > script captures the log on prompt from the server at the
> > other end, extracts the server name and saves in a file; I
> > use this to correlate the screen sessions with server names.

Why do this so complicated?
When you run screen for server "foobar", why not use
   screen -d -m -S foobar /path/to/your/script/or/command
which tells you the hostname in "screen -ls" output and allows to
   screen -r foobar
to find the correct screen session for the host you are looking
for?

> > What I want to achieve is the following:
> > 
> > 1: I want to turn on logging in screen, but not until after
> > minicom's expect script has run - otherwise the server's
> > output seems to get caught in the screen log and not in the
> > expect script. I have tried to achieve this by getting the
> > script to send a "^A:", but this just goes straight to the
> > serial line. Is there another way?

You could try to run script which could write the log file for
you, while expect does all its needed stuff.
For example, I once wrote a little shell script using the
"script" command to write a log file of the actions that I
triggered on a host like this:
    #!/bin/sh
    if [ -z "$1" ] ; then
        command=/bin/sh
    else
        command=$1
        shift
        case $command in
            *help)
                echo "Usage: $0 \"command to run\" [directory for scriptfiles]"
                echo "       If a command is not given, /bin/sh will be run."
                echo "       If a directory for scriptfiles is not given, the 
current directory"
                echo "       is being used."
                exit 1
                ;;
            *)
                echo -n "Running xterm"
                ;;
        esac
    fi

    if [ -z "$1" ] ; then
        logdir=$PWD
    else
        logdir=$1
        shift
        if [ ! -d "$logdir" ] ; then
            echo "Directory $logdir does not exist, can't write script files."
            echo "EXITING NOW!"
            exit 2
        fi
    fi
    echo -n " with scriptfile"

    DATE=`date "+%Y%m%d.%H%M%S"`

    c=`echo $command | sed -e 's/ /_/g' -e 's#/#_#g'`

    echo -n " '$logdir/typescript.$c.$DATE.$$.log' and command '$command'..."

    SHELL=/bin/sh xterm -T "$command" -e expect -c "spawn script -a -f 
$logdir/typescript.$c.$DATE.$$.log" -c 'expect "Script started"' -c "send 
\"exec $command\\n\"" -c interact &

    echo " Done."

This way, I could just use something like this:
for host in host1 host2 host3 ; do
   run_script_in_xterm_with_command "ssh address@hidden cat /etc/issue"
done
to get the contents of /etc/issue on all hosts in the logfiles of
the form
address@hidden
                                         ^^^^^^^^ ^^^^^^ ^^^^^
                                         current  current pid
                                         date     time    of shell
                                                          running
                                                          
run_script_in_xterm_with_command

Maybe that helps you?

> > 2: I also want to avoid logging the screen formatting codes -
> > is there a way to achieve this?

Not an easy one, because you would have to remove all escape
sequences from the output which is not easy because there are
many of them that are subtly different and make it hard to match
in a regular expression.
On the other hand, you can tell script to write timing
information for you into a second log file and then use the
"replay" command to see everything from the beginning of the
session in the same speed as it was running before. You can even
tell "replay" to replay at higher speed, maybe that also helps :)


> > I suppose I could find a way around both issues, eventually,
> > but it would be nice not to have to.

Maybe you don't need #1 in the way you thought because my script
already uses expect and you could just add your additional stuff
at the point where I put the "interact" command, and maybe you
don't even need expect to find out the hostname for you to write
to a logfile. Perhaps problem #2 just vanishes on the way
implementing another solution to #1 :)

> Perhaps don't use screen+minicom, but use conserver 
> (http://www.conserver.com/)?
> Also see article in SysAdmin: 
> http://www.samag.com/documents/s=9842/sam0514b/0514b.htm

Never heard of conserver before. Maybe I should have a look at it
:)

Ciao,
Thomas

-- 
 Thomas Köhler       Email:       address@hidden
     <><             WWW:              http://gott-gehabt.de
                     IRC:                           tkoehler
                     PGP public key available from Homepage!

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]