My shellscripts takes really long time to run, around 30 minutes, but if I leave and go out for lunch I doubt that:
1: will putty session closes if the script is running?
2: if putty session closes then the script will exit out.
If I use nohup scriptname
will it be fine?
Answer
PuTTY (or any other SSH client) does not care if you are looking at the screen or out to lunch. It will not close a session on its own.
A session will be closed only if:
- You close it manually (e.g., type
logout
, Ctrl+D,exit
, etc etc) - There is an auto logout or idle trigger set in your shell.
- The network connection dies.
The latter should not happen randomly, though poor equipment might 'helpfully' close connections when they think they are idle. This usually happens with SOHO equipment which come with very little memory and agressively close connection when they guess they are no longer used.
So far for puTTY and sessions. As for nohup
, let's dive a little deeper.
In ye early days people used phone lines and modems to dial in. Sometimes that connection did die. In that case the shell gets a signal that the line has detected a hangup. (signal 1, HUP).
When that happens the shell would signal the running programs with SIGHUP, which basically meant 'the phone line dropped. Please shutdown neatly. (close files, save if needed etc etc).
When you log out or when puTTY (ssh) dies the same happens.
If you run a program with nohup
then two things happen:
- SIGHUP gets ignored. So the program does not shut down.
- Standard output gets written to a file (default:
nohup.out
) rather than to the TTY.
If I use
nohup scriptname
will it be fine?
If you use nohup scriptname
and the script does not need any input, then yes, that will be fine. If you want to see the output from the script while it is running you can tail the logfile.
nohup scriptname &
tail -f nohup.out
Besides nohup
there are at least two other interesting options:
Both allow you not only to survive a disconnected line, but also to reattach a terminal at a later time.
Example:
Sitting behind a computer-1, logged into server-1
screen
Starts screenmake bzimage
Whatever task/script you want
Ctrl+A, Ctrl+DDetach;
screen
seems to have endedlogout
Logout
At this point screen
is still running and providing a shell for your script.
Let's say you go home, sit down behind your own desktop and ssh to server-1,
ssh server-1.work.tld
username
passwordscreen -r
(Continue a previously added screen)︙
Continue where you left off at work.
No comments:
Post a Comment