|
Prev: New shell service (Debian / non-profit)
Next: Opening a File via Pipes, Redirection and direct access and its effect on Command
From: laredotornado on 14 Apr 2008 21:46 Hi, I'm using Fedora Core 6 Linux. When I run the below command nohup sh /opt/scripts/backup_web.sh & the file "nohup.out" is produced in the directory where the command is run. How can I set things up such that the nohup.out file is always written to /tmp/nohup.out ? Thanks, - Dave
From: Ian Petts on 14 Apr 2008 23:23 > I'm using Fedora Core 6 Linux. When I run the below command > > nohup sh /opt/scripts/backup_web.sh & > > the file "nohup.out" is produced in the directory where the command is > run. How can I set things up such that the nohup.out file is always > written to /tmp/nohup.out ? The nohup.out file is where the output of your script is going by default. Redirect it manually if you need the output in another file or directory: nohup sh /opt/scripts/backup_web.sh > /tmp/nohup.out 2>&1 & Regards, Ian.
From: Ian Petts on 14 Apr 2008 23:25 > The nohup.out file is where the output of your script is going by > default. I didn't phrase that right. The output of your background process is going there by default. Cheers, Ian.
From: Chris Mattern on 15 Apr 2008 14:05 On 2008-04-15, laredotornado <laredotornado(a)zipmail.com> wrote: > Hi, > > I'm using Fedora Core 6 Linux. When I run the below command > > nohup sh /opt/scripts/backup_web.sh & > > the file "nohup.out" is produced in the directory where the command is > run. How can I set things up such that the nohup.out file is always > written to /tmp/nohup.out ? > "nohup" always sends stdout and stderr to "nohup.out" in the current directory; this is not configurable. However, if nothing is written to stdout and stderr, nohup.out is not created. Thus, done this way: nohup sh /opt/scripts/backup_web.sh >/tmp/nohup.out 2>&1 & nohup will not produce a nohup.out as you've redirected stdout and stderr elsewhere. Note that using generic names like "nohup.out" in /tmp is a bad idea because another process may be trying to use that name at the same time; "nohup$$.out" so it gets distinguished with the process number would be better. -- Christopher Mattern NOTICE Thank you for noticing this new notice Your noticing it has been noted And will be reported to the authorities
From: Wayne on 15 Apr 2008 16:35
Chris Mattern wrote: > On 2008-04-15, laredotornado <laredotornado(a)zipmail.com> wrote: >> Hi, >> >> I'm using Fedora Core 6 Linux. When I run the below command >> >> nohup sh /opt/scripts/backup_web.sh & >> >> the file "nohup.out" is produced in the directory where the command is >> run. How can I set things up such that the nohup.out file is always >> written to /tmp/nohup.out ? >> > "nohup" always sends stdout and stderr to "nohup.out" in the current > directory; this is not configurable. However, if nothing is written > to stdout and stderr, nohup.out is not created. Thus, done this way: I don't think this is true, at least not on my Linux/Gnu system: nohup sh -c ':' still produces an empty nohup.out file. > nohup sh /opt/scripts/backup_web.sh >/tmp/nohup.out 2>&1 & Correct, but be careful: nohup sh -c 'foo >/tmp/nohup.out$$ 2>&1' & still creates an empty nohup.out in the current directory. Use: nohup sh -c 'foo' >/tmp/nohup.out$$ 2>&1 & instead. > > Note that using generic names like "nohup.out" in /tmp is a bad idea > because another process may be trying to use that name at the same time; > "nohup$$.out" so it gets distinguished with the process number would > be better. Excellent advice. Consider using 'mktemp' if available, and setting 'TMPDIR' to '~/tmp' (which you should create, with access only to the owner). -Wayne |