I would like to run a script on remote Ubuntu PC (AWS).
while true; do timeout 1h python worker.py --log-level=ERROR; done
works well, but when I add nohup
:
nohup while true; do timeout 1h python worker.py --log-level=ERROR; done &
it returns me the error -bash: syntax error near unexpected token 'do'
.
What is the right syntax?
The answer is the same as usual - it depends. nohup catches the hangup signal while the ampersand does not.
The nohup command only writes to nohup. out if the output is otherwise to the terminal. If you redirect the output of the command somewhere else - including /dev/null - that's where it goes instead.
To run a nohup command in the background, add an & (ampersand) to the end of the command. If the standard error is displayed on the terminal and if the standard output is neither displayed on the terminal, nor sent to the output file specified by the user (the default output file is nohup. out), both the ./nohup.
Nohup, short for no hang up is a command in Linux systems that keep processes running even after exiting the shell or terminal. Nohup prevents the processes or jobs from receiving the SIGHUP (Signal Hang UP) signal. This is a signal that is sent to a process upon closing or exiting the terminal.
Try
nohup bash -c 'while true; do timeout 1h python worker.py --log-level=ERROR; done'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With