views:

431

answers:

3

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

+1  A: 

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.

Asaph
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?
nur
+6  A: 

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...

Alex Martelli
thanks. how can i access syslog using python language?
nur
@nur, `import syslog` of course -- see http://docs.python.org/library/syslog.html for all the details!
Alex Martelli
@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
@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).
Alex Martelli
+1  A: 

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

gnibbler