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.
./backup.sh >backup.logIncorrect. 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.
fg ./backup.sh >backup.logIncorrect. 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
- Use a disposable process or test shell when checking lifecycle commands.
- Exact output and option names can vary slightly by distribution and tool version.
Foundation review
Place the operation
nohup addresses the hangup signal, redirection addresses persistence of output, and an ampersand addresses shell waiting.
Check the side effect
For long-lived interactive work, screen or tmux can preserve a session as well as the process output.