LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-12-2016, 12:09 PM   #1
paperbagperson
LQ Newbie
 
Registered: Mar 2016
Posts: 10

Rep: Reputation: Disabled
Why Can't I Fork ssh Command into Background?


So a bit of background, I'm having issues with my port forwarding scripts as they do not actually kill themselves after the time I set.

Here's what I currently have:
Code:
ssh -f -g -L 8080:host:80 user@host sleep 3600
I've been testing out the command timeout:
Code:
timeout 10 ssh -f -g -L 8080:host1:80 user@host1
but when I try to run the command I get the following:
Code:
Cannot fork into background without a command to execute.


I've also been looking into creating a config file just for these types of commands, but I don't see any values I can set to always kill the tunnel (TCPKeepAlive, ServerAliveInterval, are all based on data transfer)

Basically my main question is why am I unable execute the timeout command when I force it to the background?


A few other questions:
1) can you think of a way to get the connection to kill itself after an hour no matter what?
2) What data is being transferred when you're connected to a host but not running any commands (basically why is ServerAliveInterval not terminating if I ssh and do nothing)?
 
Old 05-12-2016, 01:06 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Code:
     -N      Do not execute a remote command.  This is useful for just forwarding ports
             (protocol version 2 only).
 
1 members found this post helpful.
Old 05-12-2016, 01:28 PM   #3
paperbagperson
LQ Newbie
 
Registered: Mar 2016
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by AlucardZero View Post
Code:
     -N      Do not execute a remote command.  This is useful for just forwarding ports
             (protocol version 2 only).
Not sure if this is what you intended, but you pointing this out made me realize this is why my sleep command isn't working, some of my commands involved -N!

Thanks

... It's what I get for copying a command from the internet

Last edited by paperbagperson; 05-12-2016 at 01:41 PM.
 
Old 05-12-2016, 08:25 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,323
Blog Entries: 28

Rep: Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141
It sounds as if you might want to look at screen or tmux.

Both of them allow you to detach from terminals and reconnect to them later.
 
Old 05-12-2016, 09:37 PM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by paperbagperson View Post
... It's what I get for copying a command from the internet
In that case you might want to re-evaluate the -g option as well, which you seem to have included above.
 
  


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
Put a job in the background by suffixing &, is it fork and exec from command line? fanoflq Linux - Newbie 12 03-23-2016 01:53 AM
Can I fork a foreground child process in a background process? henryyao Linux - Newbie 1 09-06-2013 03:32 PM
Command over SSH won't go in to background buee Linux - Newbie 3 10-16-2010 07:45 AM
Simulating SSH Timeout using Fork aarontwc Programming 11 11-28-2008 10:13 PM
ssh -> perl -> spawn background proces hangs ssh session rhoekstra Programming 2 04-25-2006 01:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:37 PM.

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