Start backup.sh from an SSH shell.
Combine standard output and error in backup.log and keep the process running after the terminal disconnects.
Which command is appropriate?
nohup makes the command ignore SIGHUP, while & starts it in the background. Redirecting both output streams preserves a log.
Detailed explanation
nohup ./backup.sh >backup.log 2>&1 &Correct. nohup protects the process from hangup and the redirections capture both output streams.
Correct. nohup protects the process from hangup and the redirections capture both output streams.
./backup.sh >backup.logIncorrect. This leaves the process attached to the shell and redirects only standard output.
Incorrect. This leaves the process attached to the shell and redirects only standard output.
jobs ./backup.sh &Incorrect. jobs lists shell jobs and does not start backup.sh.
Incorrect. jobs lists shell jobs and does not start backup.sh.
fg ./backup.sh >backup.logIncorrect. fg brings a job to the foreground and does not protect it from logout.
Incorrect. fg brings a job to the foreground and does not protect it from logout.
Try it yourself
An example you can run in a temporary verification environment.
nohup --help | headExpected result
nohupのhelp。長時間processは起動しないKey points
- nohup
- SIGHUP
- Redirection
Notes
- Environment: GNU coreutils 9.x help
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.