Subject: Detect whether attached or detached from screen session?

From: "Sven Hazejager" <[email-masked]>
Date: Mon, 13 Oct 2008 16:12:52 +0200

Hi all,

I'm using screen to keep some applications open over a remote SSH
connection that sometimes is killed. What I would like to do, is to
somehow find out whether I am logged in (attached) or disconnected
from the screen session.

Reason is that I want procmail to send incoming mail to my BlackBerry
if I'm disconnected, but NOT do that when I'm SSH-ing into my Pine
session.

Using ps to see if Pine is active doesn't work of course, because it
always runs, even when screen is detached...

Any suggestions?

Thanks!

Sven

_______________________________________________
screen-users mailing list
[email-masked]
http://lists.gnu.org/mailman/listinfo/screen-users

---

From: [email-masked] (Trent W. Buck)
Date: Tue, 14 Oct 2008 15:32:10 +1100

"Sven Hazejager"

> if I'm disconnected, but NOT do that when I'm SSH-ing into my Pine

I don't know how to achieve that, but perhaps there's a different
approach to the problem -- such as always forwarding all mail to an IMAP
server that you can access from both the blackberry and from pine.

---

From: Peder Stray <[email-masked]>
Date: Tue, 14 Oct 2008 07:15:50 +0200 (CEST)

> server that you can access from both the blackberry and from pine.

The screen-socket has execute permissions when attached, and none when 
detached, like this:

attached:

ls -l /tmp/uscreens/S-peder/4598.irc
prwx------ 1 peder peder 0 Oct 14 00:00 /tmp/uscreens/S-peder/4598.irc

detached:
ls -l /tmp/uscreens/S-peder/4598.irc
prw------- 1 peder peder 0 Oct 14 07:06 /tmp/uscreens/S-peder/4598.irc

Guess you can test for that i procmail by something like:

:0c
*? perl -e 'exit ! grep { (stat $_)[2] & 0100 } </tmp/uscreens/S-peder/*>'
[email-masked]

-- 
   Peder Stray

---

From: Mark Eichin <[email-masked]>
Date: Tue, 14 Oct 2008 11:41:00 -0400

Peder Stray <[email-masked]> writes:

>> approach to the problem -- such as always forwarding all mail to an
>> IMAP server that you can access from both the blackberry and from
>> pine.
>

Parsing "screen -ls" output (for "Attached" or not) might be less
sensitive to implementation details, but that's a pretty clever test...

I'm not familiar with procmail, but it might be cleaner to use

  ! test -x /tmp/uscreens/S-peder/*

(to avoid starting perl on every message - I think both of these
assume there's only one socket that matches the rule, though it's
pretty easy to change if not...)

---

From: Peder Stray <[email-masked]>
Date: Tue, 14 Oct 2008 22:30:14 +0200 (CEST)

On Tue, 14 Oct 2008, Mark Eichin wrote:

> (to avoid starting perl on every message - I think both of these assume 
> there's only one socket that matches the rule, though it's pretty easy 
> to change if not...)

True, perl is bigger than test, but i guess you mailserver should be real 
slow for you to actually notice :)  The perl test actually checks for any 
attaced screen, so it should work for cases where there is more than one 
socket in the dir.  Using the test-line as above would break violently in 
that case since it expect only one argument.  Parsing the output from 
screen -ls would of course be even more expensive that either perl or 
test.

Of course, all of this expects that screens tmp-dir is available on the 
mailserver, which it may not be.  In that case, it may be easier to make a 
wrapper for screen that touches a statusfile before starting screen and 
maybe doing the perl-test after and remove the file if no screens are 
attached (so you actually can attached more than once to the screen)

-- 
   Peder Stray