Reputation: 23
I'm currently writing a bash script which periodically checks for some special words in the server output of a detached screen session, but it enters the session (if grep found something) instead of showing the grepped output. Here is what I've tried:
screen -r foo | grep bar
This gives me the correct return code, but doesn't detach the session afterwards! I also tried && screen -d
but that changes nothing.
So how can my script tell me if "bar" is in the output of the server running in my "foo" screen session?
Upvotes: 2
Views: 4122
Reputation: 42724
Your problem, I think, is that screen
doesn't output in a way that can be searched by grep
. If it did, then your attempt at screen -r foo | grep bar && screen -d
would likely have been the right way to go about it.
I'd suggest starting the initial screen
session with the -L
option to enable logging. Then you can search the log file for the value you want.
Upvotes: 2