3

I run my Java code from bash script using a command like this:

exec nohup "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" com.myClass "$@" &

Which creates the output file nohup.out and this file has permissions like this:

-rw------- 1  24308657 Mar 24 12:52 nohup.out

I want the group to have read permission as well, not only the user that ran the command.

How do I do this?

2
  • 1
    What are your default permissions/what is the umask? Do all created files get this permission? (E.g. test with touch foo).
    – Hennes
    Mar 24, 2015 at 18:34
  • This answer will also solve the permission case, assuming the umask is set to 022 (usually this is the default): stackoverflow.com/a/4549515/1519522 -- though the out file name must be set, either to nohup.out, or any other name.
    – aff
    Dec 10, 2018 at 14:17

3 Answers 3

2

You could add a permissions change in your command by using the “and” operator (&&) like this:

exec nohup "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" com.myClass "$@" && chmod g+r nohup.out &
3

Create the nohup.out file before you run nohup. If necessary, give it the correct permissions when you create it.

touch nohup.out && nohup seq 1

Which would then create the file with your default permissions before nohup is actually run:

-rw-r--r-- 1 rici rici 6 Mar 25 14:57 nohup.out

nohup would then append it’s output to that nohup.out file.

0
1

Can you change the permissions the normal way?

chmod g+r nohup.out

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .