1846658 Members
3293 Online
110256 Solutions
New Discussion

Re: nohup command

 
yc_2
Regular Advisor

nohup command

Hi,

I have used the nohup command in a script and was running fine. I decided to put the script into cron job, it runs fine but there is no nohup.out.

Appreciate any advise.


YC
9 REPLIES 9
Madhu Sudhan_1
Respected Contributor

Re: nohup command

It must be there check out at "/" .

...Madhu
Think Positive
yc_2
Regular Advisor

Re: nohup command

Hi Madhu,

I have checked "/" but not available. Is there a way to specify where the nohup.out to go to.


YC
Bill Hassell
Honored Contributor

Re: nohup command

It's important to note that cron is a different user and runs the jobs on your behalf. And cron does not login to run the job so nothing in /etc/profile or .profile will be run unless you put it into your job. Rather than rely on stdout and stderr using some default pathname, explicitly code a redirection, something like this:

nohup /full_pathname/your_program >> /var/tmp/your_log 2>&1

This will append all output from nohup into the file named above.


Bill Hassell, sysadmin
Madhu Sudhan_1
Respected Contributor

Re: nohup command

Hi Bill !

Since cron is run by root, the nohup.out should be created at home directory of root which is "/" (According to man pages).

Because I have run a script at cron which creates a file (Not giving absolute path name). It created at "/".

It should be the same for nohup as well.

Thanks,
...Madhu
Think Positive
yc_2
Regular Advisor

Re: nohup command

Hi Madhu and Bill,

Sorry for the confusion, I ran the cron job by su - "login name" -c "Command to execute the script".

In the script, it "cd" to the directory to perform the necessary which it had. I expected the nohup.out to be generated in that directory as it was all the while through command line but it doesn't exist in this case.


Rgds,
YC
Steffi Jones_1
Esteemed Contributor

Re: nohup command

Hello,

it might sound simple, but did you run a find command to see if the file exists on your system?

Try

find / -name nohup.out

That might give you a hint where the file is. If you can't find any nohup.out file, then please provide us with more information on how the cronjob is setup exactly.

Steffi Jones
yc_2
Regular Advisor

Re: nohup command

Hi,

I will be trying Bill Hassel's suggestion but like to find out how to put the "&" for background job.

Example:
Original statement is:
nohup /full_path/my_program&

should the new statement be (1) or (2)

(1) nohup /full_pathname/my_program >> /var/tmp/your_log 2>&1 &

or

(2) nohup /full_pathname/my_program& >> /var/tmp/your_log 2>&1


Rgds,
YC
Dan Hetzel
Honored Contributor

Re: nohup command

Hi Leong,

Both ways are correct. It's a matter of preference.
I would write it the first way, because the ampersand at the end makes the background status more obvious.

Best regards,

Dan

Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Philip Chan_1
Respected Contributor

Re: nohup command

Both statements would work but in a cron job you should do it like statement 2, because that trailing aperand is not needed.