LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-10-2016, 07:47 AM   #1
jambroo
LQ Newbie
 
Registered: Feb 2016
Posts: 2

Rep: Reputation: Disabled
Power cut during SSH session question


Hi,

I am just wondering what happens to an SSH session when a power outage occurs on your client PC. If I am SSH'd in an running an script that takes a long time and your connection abruptly ends does the command finish running or cancel as soon as the connection stops? Does it depend on the type of connection?

Say I ssh in using:
Code:
ssh user@server
And once in I run the script test.sh, which takes ~10min to complete
Code:
./test.sh > ~/output
If my client PC is switched off 30sec into running this command is ~/output just filled with whatever was output up until 30sec?
 
Old 02-10-2016, 07:49 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
^ i think so. check out the nohup command.
 
Old 02-10-2016, 07:56 AM   #3
jambroo
LQ Newbie
 
Registered: Feb 2016
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks heaps schneidz,
Code:
nohup $(./test.sh > ~/output) &
did the trick
 
Old 02-10-2016, 08:27 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
"HUP" stands for "Hang Up," as in "(300 baud) teletype modems." The user switched-off the terminal or hung-up the phone ... or their cat did it, as the case may be. Or, you disconnected the SSH, or closed the window, or what have you. "Bottom line is, you went away." SIGHUP will be sent to all processes. Their ordinary response is to terminate.

The "nohup" command instructs the process to ignore this signal: to keep running.
 
Old 02-10-2016, 10:25 AM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Another option is to run your command inside "screen". With nohup, once you press enter, the process is "gone". By that I mean if it prompts you for something, pauses, etc., there's nothing you can do it interact with it again. With screen, you can disconnect and reconnect to the shell session that's running the script whenever you want. Of course the disadvantage of screen is that even when the process finishes, the screen session will still be sitting there waiting for you to close it, with nohup it'll just exit quietly.

Which method you should use depends on the process you're running. For the process in this thread, I agree that nohup is probably the better option, but there are many other instances where screen would be better suited.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
make commands keep running after leaving a terminal session or ssh session Danny3031 Programming 18 01-30-2012 11:29 AM
Power cut, now harddrive has no filesystem HELP davidb2002 Linux - Hardware 1 03-29-2010 11:45 AM
power company idiots cut power while system was on, now hangs at boot with # prompt shroomy_bee Linux - Newbie 10 07-04-2008 12:12 AM
Power cut and internet robingazi Debian 2 08-25-2006 09:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration