LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-17-2006, 10:32 AM   #1
microsoft/linux
Senior Member
 
Registered: May 2004
Location: Sebec, ME, USA
Distribution: Debian Etch, Windows XP Home, FreeBSD
Posts: 1,445
Blog Entries: 9

Rep: Reputation: 48
ssh question


If I ssh into a machine, run 'aptitude update' and 'aptitude dist-upgrade' and then close the Putty window before the update finishes, will it cancel the job? I should probably know this, but I want to make sure.
 
Old 02-17-2006, 01:36 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
It depends on whether the command was designed to background itself or not.

When you close a session it sends a SIGHUP (hang up) to the processes. If they were designed to respond to that they'll shut down. Some processes are designed to ingore it.

However you can force it to ignore the SIGHUP and keep running in the background by starting it with the nohup command and ending with the ampersand (&). The nohup tells it NOT to accept a SIGHUP and the ampersand tells it to run in the background.

nohup aptitude update &

As to whether its wise to run "aptitude" that way I can't say as I've never done it. If it expects input at any point it will sit there until you kill the process as you won't be able to interact with it.
Example: doing "nohup vi /var/log/messages &" would not be a good idea. It would certainly start the vi session but since it wouldn't be associated with a terminal you couldn't do any edits and you'd have to kill the process to get rid of it.

FYI: When you do the background it tells you the PID of the process it starts.
 
Old 02-17-2006, 02:13 PM   #3
microsoft/linux
Senior Member
 
Registered: May 2004
Location: Sebec, ME, USA
Distribution: Debian Etch, Windows XP Home, FreeBSD
Posts: 1,445

Original Poster
Blog Entries: 9

Rep: Reputation: 48
you can foreground a backgrounded process though right? I think aptitude generally looks for the user to hit 'enter' at the end. I suppose I could use apt-get instead, which, if I recall correctly, doesn't.
 
Old 02-17-2006, 02:36 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Yep fg/bg are used to toggle foreground/background in many shells. I haven't really played with that much though.

Better yet you could use the "screen" command. This allows you to open a session on a terminal then close that terminal and later go back to the same session from that or any other terminal.

Some of the notes I had on screen usage (been awhile since I used it):

screen -list - Shows screen session names
screen -S <name> - Starts screen session and gives it <name> as name.
screen -x <pid> - Attaches to existing screen session with PID of <pid>.(12-Sep)
screen -x <name> - Attaches to existing screen session named <name>.(NO! 12-Sep)
Ctrl-A - Main command to use within screen. Selected options:
Ctrl-A ? - Gives a list of all options
Ctrl-A 0 - Goes to first window within a screen session.
Ctrl-A 1 - Goes to second window within a screen session.
Ctrl-A <n> - Goes to nth window within a screen session.
Doing exit from within a screen session will fall back to previous window.
Doing exit from all windows in screen session will terminate screen.
Closing window that has a screen session will leave it running and detached.
 
Old 02-17-2006, 02:49 PM   #5
microsoft/linux
Senior Member
 
Registered: May 2004
Location: Sebec, ME, USA
Distribution: Debian Etch, Windows XP Home, FreeBSD
Posts: 1,445

Original Poster
Blog Entries: 9

Rep: Reputation: 48
so this wouldn't work? Basically, I'm trying to update via ssh, and I'm using PuTTy, so if I close the window, it essentially logs me out.
 
Old 02-17-2006, 03:10 PM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Sorry - My notes are written for me so are often a little confusing to others - I just cut and pasted.

It will work so long as you don't type "exit" or hit "Ctrl-D" to close the window. If you just close it with the little X at the top of the window it is OK.

Having said that:
I use PuTTY now but at the time was using a licensed version of OpenSSH on my Windows workstation. I see no reason that should make a difference but can see the possibility so didn't want you to think I'd led you astray.

You can test screen using the vi example. At worst you'll just have to kill the vi process. Once you've got the hang of it you can use it for aptitude.

When I used screen at that prior job I used it a lot and never had an issue once I'd figured it out. The notes were written to remind me of what I'd figured out.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH Question kinetik Linux - General 4 02-15-2006 11:01 PM
ssh question zeviddalop Linux - General 5 01-27-2005 02:24 AM
ssh-agent/ssh-add question mega Slackware 2 01-26-2005 03:09 AM
SSH Question JockVSJock Slackware 2 11-11-2004 07:00 PM
question about ssh erikm103 Linux - General 2 03-11-2003 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:35 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