How long can a Screen session I start on a server run for, if I detach and disconnect
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
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 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.
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 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.
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?
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?
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.
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.
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"
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.
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.
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.
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:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.