0

It seems that umask and nohup don't work correctly together.

I did this:

$ umask 022
$ nohup java -jar blah.jar &
[1] 12345
nohup: ignoring input and appending output to `nohup.out'
$ ls -l nohup.out
-rw-------. 1 juser juser 41242 Jun 27 11:07 nohup.out

Any idea why? Is it nohup that forces 600 ignoring umask settings? How can I get nohup.out to be created with 644 permissions instead than 600? OK, I can do a chmod 644 nohup.out, but I'd prefer a "clean" approach.

My shell is bash, my OS is CentOS 7.

3

GNU’s implementation of nohup ignores umask:

Any nohup.out or $HOME/nohup.out file created by nohup is made readable and writable only to the user, regardless of the current umask settings.

This only applies when nohup itself creates the file, so you can create nohup.out with the appropriate permissions before running nohup, and nohup will append to it without changing the permissions:

umask 022
touch nohup.out
nohup java -jar blah.jar &

or even use a redirection to get the shell to create the file for you:

umask 022
> nohup.out nohup java -jar blah.jar &
  • 1
    It works also with a nohup java -jar blah.jar > nohup.out 2>&1 & Indeed, thank you. – Sampisa Jun 27 '19 at 13:29
  • Ah yes, that’s a nice variant, getting the shell to create the file for you. – Stephen Kitt Jun 27 '19 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.