Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

In a bash script, I use "screen -L" to log executed commands in color. For example :

   screen -L tree

Then we read logfile with less -R.

When this script is executed, other screens are potentially running so we don't know which screenlog.* contains our output. I can't demand the user to customize his .screenrc.

Is there a way to specify a log name on command line or to read specific .screenrc commands.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

I have a couple thoughts on this. First, note you can control the startup screenrc when invoking screen via the -c command line switch. Second, you can use environment variables in your .screenrc. Putting this all together, here's a shell script to do something like what you want:

#!/bin/bash

cat << EOF >/tmp/screenrc.$$
logfile /tmp/screenlog.$$
EOF

screen -c /tmp/screenrc.$$ -L
rm /tmp/screenrc.$$

echo "logfile is /tmp/screenlog.$$"

that script overrides the user screenrc and places the output in a specific file. In this case I'm using $$ to generate the file name by appending the script process name. Note that you should generally use mktemp instead to create secure temporary files but I'm lazy right now.

Also this completely replaces the user .screenrc. If you want to still read settings from that file, you should change the generated config file to something like this:

logfile /tmp/screenlog.$$
source $HOME/.screenrc
share|improve this answer

Why don't you do:

tree -C > tree.log

The -C option forces color on even when output is not to a tty. Similarly:

ls -l --color=always > ls.log
grep --color=always foo bar > grep.log
ack --color foo > ack.log

Utilities that output color often have ways to force it on when output is sent to a pipe or redirected.

share|improve this answer
    
After re-reading the question, my suspicion is that something like this might be more what's really needed. –  Phil Hollenback Mar 17 '11 at 20:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.