Mo J. Mughrabi
Mo J. Mughrabi

Reputation: 6997

how can i run a linux process in the background and log the nohup output

am trying to run a nohup process to be in the background. The process is firing successfully but for some reason its creating a nohup.out file in the location where I fire the process.

nohup bash -c "./manage.py celeryd -B -E -l DEBUG &> ../../logs/celeryd_beat.nohup &> ../../logs/celeryd_beat.err" &

Is there a way so i can make the nohup outputs into ../../logs/celeryd_beat.nohup?

regards,

Upvotes: 0

Views: 8552

Answers (3)

tripleee
tripleee

Reputation: 189407

It is a feature of nohup to save output to nohup.out if you do not redirect it. Since you appear to already be saving all the output you want, you can just add >/dev/null 2>&1 at the end, just before the final &. (What's with the outer bash -c, though? It looks completely unnecessary to me.)

Upvotes: 0

David Z
David Z

Reputation: 131600

Sure, if you look at the man page for nohup it says

To save output to FILE, use `nohup COMMAND > FILE'.

(at least that's on my system, though you should check to see if yours is the same). So something like

nohup bash -c "..." >../../logs/celeryd_beat.nohup

should work for you. (I omitted your command between the quotes, but you should of course actually include it when you do this)

EDIT: Actually, now that I noticed you are redirecting standard output and standard error of the Python script itself (for which you should be using > and 2> if you want them to go to separate files - see Jim's answer), you may just want to discard the output of nohup itself, which shouldn't actually include anything. So in that case you can do

nohup bash -c "..." >/dev/null

Upvotes: 0

Jim Garrison
Jim Garrison

Reputation: 86774

Try

nohup bash -c "./manage.py celeryd -B -E -l DEBUG > ../../logs/celeryd_beat.nohup 2> ../../logs/celeryd_beat.err" &

Upvotes: 2

Related Questions