nohup ./my-script.sh >> my-output.txt 2>&1 &
nohup
stands for "no hangup", which prevents the SIGHUP (signal hangup) that is sent when closing the SSH session (or closing a local terminal) to terminate the script.
>>
it's redirecting the output and appending to a custom file, if you omit you will get the output on a file called nohup.out
.
2>&1
makes not only stdout to be redirected but stderr as well.
&
puts the command in the background and gives you the CLI back to be used.
Here's a dummy script for you to test it out:
#!/bin/bash
while true
do
echo "5 seconds just passed"
sleep 5
done
Remember to kill it after you are done!
Top comments (0)