Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use `while true` with nohup?

Tags:

bash

nohup

ubuntu

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?

like image 354
LA_ Avatar asked Aug 27 '16 11:08

LA_


People also ask

Do you need ampersand with nohup?

The answer is the same as usual - it depends. nohup catches the hangup signal while the ampersand does not.

How do I use the nohup command without getting nohup out?

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.

How do I run a nohup script in the background?

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.

What is nohup out file in Linux?

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.


1 Answers

Try

nohup bash -c 'while true; do timeout 1h python worker.py --log-level=ERROR; done'
like image 166
MariusMatutiae Avatar answered Sep 26 '22 13:09

MariusMatutiae