[SOLVED] how to run the screen program WITHOUT clearing the display
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to run the screen program WITHOUT clearing the display
I have a script which runs a few programs where the output scrolls up in the normal text way. There is one program the script runs I have a reason to run it inside screen. But I would like this program's output to just work like the others, and be output at the bottom of the display and scroll up like everything else. It will eventually finish in a few seconds, in which case it will exit, and screen should exit, and the script will go on to the next program as usual.
But screen clears the display because screen wants to manage it all. Any idea how to disable this?
from man screen ( Screen version 4.01.00devel (GNU) 2-May-06 )
Code:
-d -m Start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.
-D -m This also starts screen in "detached" mode, but doesn't fork a new process. The command exits if the session terminates.
No idea if that fits your context, no real context to fit.
It needs to stay attached so it's output is shown and scrolls up like other output in the script, from the other programs it runs. I just don't want it blanking out the previous output. Someone watching the display should not really seen that screen was even run, although a few lines of output at the start and end could be tolerable. The program that will be run in screen will output about 3 to 6 lines. Those lines need to be seen below the output from previous programs, and above the output of programs that are run afterwards.
I'm using the detached method now, and I cannot see the output of the program being run.
I don't know if this will be suitable, but -L will produce an output log, which you could then view with cat screenlog.0
I was going to say use tail -f, but that tail will never exit.
Dumb example
Code:
#!/bin/bash
for i in {1..9};do
echo "line $i"
done
rm screenlog.0
coproc screen -DmL df -h
sleep 1
cat screenlog.0
for i in {9..18};do
echo "line $i"
done
Probably Doesn’t fit..
I don't know what you are running in your screen session or where that screen is ( local/remote or if brand new )
The task being run in screen is an rsync command to transfer /root/.ssh files over to the target host. It uses ssh. The very first time there will be an ssh password prompt. Screen is being used to stuff in the password to ssh which reads it from /dev/tty instead of stdin. Thereafter I can use ssh keys, so this is just a one-time thing per host. I start the background thing like this:
This works, but I want to see the rsync command output in the scrolled output. If I take out the "-d" then I do see the output, but with the display blanking happening.
here I have used -Dm instead of -dm, this is so I can get pid of last bg job ( with $! )
by default screenlog.n ( where n is screen number ) is in current working dir, to change this you have to customise the .screenrc file ( unless things have changed and you can specify on command line, which would be much nicer )
I want to avoid doing it by PID because -Dm is still blanking the display. Using -dm drops it in the background so I cannot reliably get the PID. But I don't need the PID since fuser can tell me when the file is no longer open.
Here's what I have lately tried:
Code:
echo "Testing if ssh can login using a key pair"
ssh=( ssh -o 'batchmode yes' "root@${dsthost}" )
rsync=( rsync -e 'ssh -o "batchmode no"' -avWz ${cwd}/noarch/root/.ssh/. ${dsthost}:/root/.ssh )
if ! "${ssh[@]}" 'echo YES' ; then
if [[ -n "${PW}" ]] ; then
echo "Transferring authorized_keys file to avoid future password prompts"
pid=$$
unique=$( exec date "+%Y%m%d%H%M%S%N${pid}" )
cfgfile="/tmp/mods-rsync-${unique}.cfg"
logfile="/tmp/mods-rsync-${unique}.log"
echo "logfile ${logfile}" > "${cfgfile}"
ls -dl "${cfgfile}"
screen -c "${cfgfile}" -S mods-rsync -p 0 -dm "${rsync[@]}"
sleep 5
screen -S mods-rsync -p 0 -X stuff $( printf '%s\r' "${PW}" )
while fuser "${logfile}" 2>/dev/null ; do sleep 1 ; done
cat "${logfile}"
# rm -fv "${cfgfile}" "${logfile}"
"${ssh[@]}" 'ls -dl /root/.ssh/authorized_keys' || fail "Transfer of authorized_key file to ${dsthost} failed"
else
echo
echo 'Enter the root password for ${dsthost} to transfer the .ssh/authorized_keys file:'
"${rsync[@]}" || exit 1
fi
fi
But this still fails because the log file is not being written. I think I have it set up correctly in the config file, and -c is used to refer to the config file. And at least 5 should be enough time for the log file to be opened. Yet it doesn't write the log file. The rsync does run, does get the password being stuffed in, and does transfer the ssh files. Screen is just not logging it. Does screen need to stay in the foreground to log it (e.g. the client side does the logging instead of the server side)? If so, I'll try some other way to get log output. The output looks like this:
Code:
Testing if ssh can login using a key pair
Warning: Permanently added 'planck,192.168.1.22' (RSA) to the list of known hosts.
Permission denied (publickey,password,keyboard-interactive). this is the test on the if command
Transferring authorized_keys file to avoid future password prompts
-rw-r--r-- 1 root root 57 Jul 23 01:34 /tmp/mods-rsync-2013072301341102456990623720.cfg
cat: /tmp/mods-rsync-2013072301341102456990623720.log: No such file or directory the file is not there
Warning: Permanently added 'planck,192.168.1.22' (RSA) to the list of known hosts.
-rw------- 1 root root 71808 Oct 2 2012 /root/.ssh/authorized_keys it got this file anyway
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.