LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   How long can a Screen session I start on a server run for, if I detach and disconnect (https://www.linuxquestions.org/questions/linux-server-73/how-long-can-a-screen-session-i-start-on-a-server-run-for-if-i-detach-and-disconnect-4175541137/)

ahegao 04-29-2015 03:04 PM

How long can a Screen session I start on a server run for, if I detach and disconnect
 
Hello,

So I'm doing some work on a remote PC via SSH (inside a Screen session), and I'm noticing that I'm getting errors if I'm not connected for some amount of time. There's usually no problem if i reconnect and reattach the screen after an hour or two, but if I'm disconnected overnight, I log back and find that whatever I was doing threw an error. The screen session still exists, but the work has stopped.

Is this expected behavior?

hoes 04-30-2015 02:45 AM

I have different experiences with screen.
Session just run overnight on most servers I used.
Maybe it is somewhere in the settings of that server?

Patric.F 04-30-2015 03:07 AM

I've never had that issue with screen at all. I have a screen session without being attached to it for days and it runs just fine 24/7.
Maybe it's the program that you are running inside the screen that is the problem? Or do you get the same behavior if you run different programs?
I have stuff like rTorrent and Irssi in a screen session without attaching to it for a very long time and I can't say that I've experienced the symptoms you are saying.
So I would say no, it's not an expected behavior.

What distro and version of screen are you using?

/Patric

ahegao 04-30-2015 06:05 AM

its screen 4.0.3-14ubuntu.

What happens is that I have a script running on the server that constantly executes matlab, runs a single command, takes the output from console and repeats (dont ask. ugh. )

I just left my client PC open overnight, the putty session had keepalive 1800 configured, and the ssh gateway from which i connect to the server also had keepalive on the ~/.ssh/config file, and I had left one of the screens displaying 'top'

When i came back, the putty ssh session was timed out, and when I logged back in and reattached the screen, the script was crashed.

The error message was "permission denied" on the command that runs matlab.

hoes 04-30-2015 07:01 AM

I usually run screen and detach all screens before logging out of putty.
That way the commands just run without any information moving over ssh.
Did you try this as well?

ahegao 04-30-2015 07:05 AM

Quote:

Originally Posted by hoes (Post 5355608)
I usually run screen and detach all screens before logging out of putty.
That way the commands just run without any information moving over ssh.
Did you try this as well?

no i didn't. I was attached to the screen when putty timed out. Does detaching really make things work differently?

hoes 04-30-2015 07:19 AM

Yes, that is the whole point of screen.
With detaching the screen you decouple it from your putty session.
That way the command in your screen is alive even when you close your putty session.
And you can open the screen in a different login session.
I usually use a detached screen as an insurance for command that run a long time.
That way i can be sure the command continues regardless of a connection timeout.

ahegao 04-30-2015 07:21 AM

AUGH i thought that screen was independent regardless of if I was attached to it or not...

So just to understand this correctly, if I'm sshed into an attached screen and the ssh times out, this does not 'count' as detaching the screen and the screen is not independent when the putty times out and it breaks. But if i detach, it is then independent.

hoes 04-30-2015 07:44 AM

You got it.
Also look at http://www.workhabit.com/blog/best-p...h-alive-screen

ahegao 04-30-2015 04:40 PM

Ok unfortunately this didn't work.

I detached the screen this time (but had left putty open, sitting OUTSIDE of the screen tho.) After like 8 hours, the job inside the screen crashed with error "key has expired" . My SSH session didn't actually time out, but I could execute no commands inside or outside of screen. even "ls" gave error "cannot execute, key has expired"

hoes 05-01-2015 12:59 AM

But then the question is whether you can set up a new SSH connection that could attach the screen.

ahegao 05-01-2015 01:25 AM

no not really. The SSH connection had nothing to do with the timeout. The screen lost I/O permissions regardless of the SSH session. I was detached this time. And also tonight it happened again with a completely closed ssh session and a detached screen doing work.

unSpawn 05-01-2015 01:30 AM

Quote:

Originally Posted by ahegao (Post 5355882)
I detached the screen this time (but had left putty open, sitting OUTSIDE of the screen tho.) After like 8 hours, the job inside the screen crashed with error "key has expired" . My SSH session didn't actually time out, but I could execute no commands inside or outside of screen. even "ls" gave error "cannot execute, key has expired"

The "key has expired" message does not sound like something a problem with SSH or screen. What you could do to diagnose this is to start a new screen session, then key combo CTRL-A, SHIFT-H to start a screen log and then start your application and then detach. When you re-attach check stdout / stderr / screen log for the message and whatever surrounding lines and post those here if you can't fix it yourself. *Note that for running attached screen sessions for hours on end Linux has 'autossh', which re-establishes connections when they get interrupted, but obviously the Other OS doesn't offer an equivalent.

hoes 05-01-2015 01:45 AM

Also, if I google "key has expired". One of the first things that pops up is problems with samba or cifs mounts.
If you say that you cannot even do ls outside the screen the problem might not be with screen after all.

ahegao 05-01-2015 04:42 AM

Ok some clarification:

This error has happened to me over 5-6 times now AFTER I mentioned the "Key has expired" error messages. In all of those subsequent errors, the error was "Permission denied" instead, and not key has expired. So, sorry for that confusing part. I'm not sure why the 1st case had a different error message either. Maybe because i was idling in the SSH session (detached screen) instead of just logging out.

Here's the actual stderr file from my script trying to execute matlab:

Code:

sh: 1: /vol/share/software/matlab/******/r2012b/bin/matlab: Permission denied
This happens after:

1. I ssh to the target host.
2. start a screen.
3. run my job.
4. detach screen
5. log out
6. log back in a while after. Reattach screen. Everything is working normally, but process has terminated with the above error. Commands now work normally.



Quote:

The "key has expired" message does not sound like something a problem with SSH or screen. What you could do to diagnose this is to start a new screen session, then key combo CTRL-A, SHIFT-H to start a screen log and then start your application and then detach. When you re-attach check stdout / stderr / screen log for the message and whatever surrounding lines and post those here if you can't fix it yourself. *Note that for running attached screen sessions for hours on end Linux has 'autossh', which re-establishes connections when they get interrupted, but obviously the Other OS doesn't offer an equivalent.
I'm not sure if the stderr that my work already logs will produce the same output, so I'll try doing this


Quote:

Also, if I google "key has expired". One of the first things that pops up is problems with samba or cifs mounts.
If you say that you cannot even do ls outside the screen the problem might not be with screen after all.
Again, this was a special case that only happened the first time. I think it happened because i was idling in the SSH session but your guess is as good as mine honestly :/ This is very confusing. The typical behavior is as I described above.


All times are GMT -5. The time now is 01:13 PM.