user5742489 user5742489 - 3 years ago 127
Linux Question

Possible to read the last line of a linux gnu-screen?

I'm trying to make a simple and reliable script, preferably in bash, that is executed every minute using crontab. The script simply has to read the contents of the last couple of lines of an open screen and store them as a var so that I can search for a sub-string. Does anyone know of an easy way to do this, thanks.

Answer Source

You can send the hardcopy command to the screen and read the last line using the last command:

screen -X hardcopy "~/test.log"
last -1 test.log

The tail command works similarly to last.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download