How to grant a java tool write permission to /var/log?
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.
Related videos on Youtube
membersound
JEE + Frameworks like Spring, Hibernate, JSF, GWT, Vaadin, SOAP, REST.
Updated on September 18, 2022Comments
-
membersound over 1 year
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?-
ridgy almost 7 yearsDon't run the
.jar
assudo
; every mistake (wrong paths e.g.) could destroy your system. Assyslog
has write access, you might add the user to that group:adduser <user> syslog
. -
membersound almost 7 yearsThanks for you opinion. You might want to add this as an answer, so I could accept it lateron?
-
-
Hindol over 4 yearsMight 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. -
Rinzwind over 4 yearsI agree :) editted.