User avatar
stevo_300
Posts: 33
Joined: Thu Jan 26, 2012 9:38 am
Contact: Website

Persistant SSH connection

Tue Dec 04, 2012 2:02 pm

Hello,

I am wanting to remote control my PI from work (the Pi is at home)

is it possible to set a command running via a SSH session, and ensure it keeps running even if the SSH window closes so I can come back to it later for instance if building code or downloading a file.

Thanks

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am
Contact: Website

Re: Persistant SSH connection

Tue Dec 04, 2012 2:05 pm

My favorite is screen

sudo apt-get install screen

To start a new screen you type screen you can even name it

screen -S nameit

To disconnect and leave it running

CTRL+A then d

Then close ssh

To reconnect log in

Type

screen -ls

That shows what screens are running to connect to that screen say it is named 2986

screen -r 2986

Or just type screen -r 2 then hit the Tab key.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

User avatar
stevo_300
Posts: 33
Joined: Thu Jan 26, 2012 9:38 am
Contact: Website

Re: Persistant SSH connection

Tue Dec 04, 2012 2:52 pm

Fantastic, I will try this.

Thanks for your help

User avatar
stevo_300
Posts: 33
Joined: Thu Jan 26, 2012 9:38 am
Contact: Website

Re: Persistant SSH connection

Tue Dec 04, 2012 3:27 pm

Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
iselect screenie byobu
The following NEW packages will be installed:
screen
0 upgraded, 1 newly installed, 0 to remove and 113 not upgraded.
Need to get 0 B/650 kB of archives.
After this operation, 923 kB of additional disk space will be used.
dpkg: error: parsing file '/var/lib/dpkg/available' near line 12236:
EOF after field name `'
E: Sub-process /usr/bin/dpkg returned an error code (2)


I am getting this error when trying to install screen. I know this is most likely a basic issue, unfortunately I'm new to Linux and just finding my feet.

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am
Contact: Website

Re: Persistant SSH connection

Tue Dec 04, 2012 3:33 pm

try sudo apt-get update
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

User avatar
stevo_300
Posts: 33
Joined: Thu Jan 26, 2012 9:38 am
Contact: Website

Re: Persistant SSH connection

Tue Dec 04, 2012 3:35 pm

I did, it didnt make a difference

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am
Contact: Website

Re: Persistant SSH connection

Tue Dec 04, 2012 3:43 pm

sudo dpkg --clear-avail

then rebuild the file using the command:

sudo apt-get update
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

User avatar
tedhale
Posts: 114
Joined: Thu Sep 20, 2012 4:52 pm
Location: Williamsburg, VA, USA
Contact: Website

Re: Persistant SSH connection

Tue Dec 04, 2012 4:04 pm

If your program has a graphical interface, then you probably need screen (I prefer to use a VNC server on the Pi and a VNC client on my PC. Search this forum for instructions.)

If the program is text based, you can just use the nohup command to keep the program running after you log off.

When I have done this in the past I have always redirected output to a log file so I could see what the program was doing later.
- Ted B. Hale
http://raspberrypihobbyist.blogspot.com

User avatar
stevo_300
Posts: 33
Joined: Thu Jan 26, 2012 9:38 am
Contact: Website

Re: Persistant SSH connection

Tue Dec 04, 2012 4:07 pm

you are a complete legend.

All working and screen does seem to do what I wanted.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Persistant SSH connection

Tue Dec 04, 2012 8:09 pm

stevo_300 wrote:you are a complete legend.

All working and screen does seem to do what I wanted.
screen is truly awesome. Many of us have been using it for decades.

And, remember, it's not only a screen multiplexer; it's also a serial communications program.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

bulletmark
Posts: 121
Joined: Wed Oct 17, 2012 10:10 pm
Location: Brisbane Australia

Re: Persistant SSH connection

Tue Dec 04, 2012 10:51 pm

Note that screen has largely been superseded by tmux nowadays which looks slightly better, has better defaults, has horizontal screen split, etc. If you are learning something new then you may as well choose tmux.

BTW. I have used for screen for 10 years or so but use tmux almost exclusively now.

User avatar
stevo_300
Posts: 33
Joined: Thu Jan 26, 2012 9:38 am
Contact: Website

Re: Persistant SSH connection

Wed Dec 05, 2012 9:54 am

interesting, I will give it a try as well

Return to “Advanced users”