开发者

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

开发者 https://www.devze.com 2023-03-31 17:47 出处:网络
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 f开发者_开发问答ile in the location where I fire the process.

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 f开发者_开发问答ile 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,


Try

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


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


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消