[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Logging in screen
Re: Logging in screen
Fri, 14 Dec 2007 07:51:32 +0100
> 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
> > 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:
if [ -z "$1" ] ; then
case $command in
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
echo " is being used."
echo -n "Running xterm"
if [ -z "$1" ] ; then
if [ ! -d "$logdir" ] ; then
echo "Directory $logdir does not exist, can't write script files."
echo "EXITING NOW!"
echo -n " with scriptfile"
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"
to get the contents of /etc/issue on all hosts in the logfiles of
^^^^^^^^ ^^^^^^ ^^^^^
current current pid
date time of shell
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
> Also see article in SysAdmin:
Never heard of conserver before. Maybe I should have a look at it
Thomas Köhler Email: address@hidden
<>< WWW: http://gott-gehabt.de
PGP public key available from Homepage!
Description: Digital signature