3

I'm running a java tool as a command line app using cronjob: java -jar /var/java/-myfile.jar

By default I'm using logback and write to /var/log/mylogfile.log.

Problem: the user running the jar has no permissions to write to the /var/log/ folder. That folder has only permissions to `root syslog'.

Question: should I run the jar as sudo? Or should I give the running user write permissions to that folder? If yes, how?

2
  • 2
    Don't run the .jar as sudo; every mistake (wrong paths e.g.) could destroy your system. As syslog has write access, you might add the user to that group: adduser <user> syslog. – ridgy May 12 '17 at 8:31
  • Thanks for you opinion. You might want to add this as an answer, so I could accept it lateron? – membersound May 12 '17 at 8:50
4

Should I run the jar as sudo?

No. Far too dangerous since you could then change about anything to the system and a single misplaced space could remove your whole system.

Or should I give the running user write permissions to that folder? If yes, how?

Yes. The 2 main commands are to change write permissions and change the USER of your log file:

   sudo chmod 664 /var/log/{yourdir}/mylogfile.log
   sudo chown $USER:$USER /var/log/{yourdir}/mylogfile.log

where $USER is your current active user and {yourdir}/ is a directory you defined (mysql and apache for instance use their own directory in /var/log/ instead of filling up /var/log/). It is a slightly better method.

2
  • Might be slightly better to actually create a directory within /var/log and change ownership of that directory as this allows the app to create or re-create the log file. – Hindol Nov 18 '19 at 12:39
  • I agree :) editted. – Rinzwind Nov 18 '19 at 12:59

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.