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

Ask A Question

Stats

  • Questions 276k
  • Answers 276k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As you already mentioned, you need to create an instance… May 13, 2026 at 2:53 pm
  • Editorial Team
    Editorial Team added an answer It's a violation of the MVC paradigm to be using… May 13, 2026 at 2:53 pm
  • Editorial Team
    Editorial Team added an answer Here is an alternative though: why don't you Zip the… May 13, 2026 at 2:53 pm

Related Questions

This is a follow on question to How do I delete 1 file from
this is a follow up on my question on paypal integration. I'm working ona
This is a follow-up on How do you change the default widget for all
This is a follow-up to the question: Should the folders in a solution match

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.