Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 35431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:14:05+00:00 2026-05-10T14:14:05+00:00

This is a follow-on question to the How do you use ssh in a

  • 0

This is a follow-on question to the How do you use ssh in a shell script? question. If I want to execute a command on the remote machine that runs in the background on that machine, how do I get the ssh command to return? When I try to just include the ampersand (&) at the end of the command it just hangs. The exact form of the command looks like this:

ssh user@target "cd /some/directory; program-to-execute &" 

Any ideas? One thing to note is that logins to the target machine always produce a text banner and I have SSH keys set up so no password is required.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:14:06+00:00Added an answer on May 10, 2026 at 2:14 pm

    This should solve your problem:

    nohup myprogram > foo.log 2> foo.err < /dev/null & 

    The syntax and unusual use of < /dev/null are explained especially well in this answer, quoted here for your convenience.

    < /dev/null is used to instantly send EOF to the program, so that it doesn’t wait for input (/dev/null, the null device, is a special file that discards all data written to it, but reports that the write operation succeeded, and provides no data to any process that reads from it, yielding EOF immediately).

    So the command:

    nohup myscript.sh >myscript.log 2>&1 </dev/null & #\__/             \___________/ \__/ \________/ ^ # |                    |          |      |      | # |                    |          |      |  run in background # |                    |          |      | # |                    |          |   don't expect input # |                    |          |    # |                    |        redirect stderr to stdout # |                    |            # |                    redirect stdout to myscript.log # | # keep the command running  # no matter whether the connection is lost or you logout 

    will move to background the command, outputting both stdout and stderr to myscript.log without waiting for any input.


    See also the wikipedia artcle on nohup, also quoted here for your convenience.

    Nohuping backgrounded jobs is for example useful when logged in via SSH, since backgrounded jobs can cause the shell to hang on logout due to a race condition. This problem can also be overcome by redirecting all three I/O streams.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow-up to the following question: Executing ssh command in a bash
This is a follow up on this question: Can I use GNU make's SHELL
Sorry to follow this topic http://stackoverflow.com/questions/11044825/javascript-run-on-ie-7 I want to use document.GetElementByClassName ON INTERNET EXPLORE
First of all, this is a follow-up question to Should I use WCF or
Background: This is a follow-up question to this thread about handling EINTR for system
Note that this is a follow-up question from my previous one: How to memorize
This is a follow up question from here . Where I want do go
This is a follow up question to that at Can I create a HTML
this is a follow-up to question Better DateTime? or use default(DateTime) for NULL? I
This is actually a follow up question to this " Why need to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.