1

how can i create new file in /var/log directory using python language in OSX leopard? i tried to do it using os.open function but i get "permission denied"

thanks in advance

2
  • Not really a programming question. Permission issues are part of superuser.com. Commented Oct 7, 2009 at 10:21
  • its tagged as python that means "os.open" is a python function. Commented May 29, 2013 at 20:01

3 Answers 3

6

Only root can write in /var/log/ on Mac OS X...:

$ ls -ld /var/log drwxr-xr-x 60 root wheel 2040 Oct 6 17:00 /var/log 

Maybe consider using the syslog module in the standard library...

Sign up to request clarification or add additional context in comments.

3 Comments

@nur, import syslog of course -- see docs.python.org/library/syslog.html for all the details!
@alex thank u very much. actually what i want to achieve is that, i am writing a launchagent application for osx using python. it writes some meta info in a sqlite db from time to time. these data cannot be seen by user without root privilege. so i need to keep this db file in place where only root has access. how can i achieve that?
@nur, you can achieve that only by running as root (not recommended, but it IS the only way to do exactly what you ask: update a sqlite db which ONLY root can access).
1

It probably failed because /var/log has user set to root and group set to wheel. Try running your python code as root and it will probably work.

1 Comment

thank u. my application is a launchagent application. it runs during start up and saves some data in file time to time. data saved by the application cannot be viewed without root privilege. how can i achieve that?
1

You can create the log file as root and then change the owner to the user your script is run as

# touch /var/log/mylogfile # chown myuser /var/log/mylogfile 

where mylogfile is your logfile and myuser is the user the script will be run as

also look into logrotate

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.