Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a python script that parses some html and then writes it to output file. I want that cronjob would execute that python script. When I run this script from command line it works fine (python script.py).

Log file:

OSError: [Errno 13] Permission denied: '~/www/test_version/output.txt'

Cronjob:

*/1 * * * * /usr/bin/python /data/script.py 1>/data/log.log 2>&1

Part of the script:

output = "output.txt"
path = os.path.expanduser("~/www/test_version/")
absolute_path = os.path.join(path, output)
if os.path.isfile(absolute_path):
    os.remove(absolute_path)

os.path.expanduser("~")
output = open(absolute_path, "w")
share|improve this question
    
Which user's crontab have you put this in, which user does ~/www/phedex_version belong to. What are the permissions on ~/www/phedex_version? – EightBitTony Jan 18 at 9:51
    
I just used crontab -e, so not root. drwxr-xr-x. 2 cmssst zh 2048 Jan 18 10:37 test_version – Rokas.ma Jan 18 at 9:59
    
Could you do a print on absolite_path out of curiosity? Having a hard time believing the error vs the code you're using since it still uses a relative path in its name during error prompt. – Torxed Jan 18 at 10:09
    
/afs/user/c/cmssst/www/test_version/output.txt. I it's correct path – Rokas.ma Jan 18 at 10:13
    
So can you add the following to your question (rather than here as a comment), permissions on the ~/www/test_version/output.txt directory, any permissions on the output.txt file if it already exists. You might want to check the permissions on /afs, /afs/user, /afs/user/c, /afs/user/c/cmssst, /afs/user/c/cmssst/www as well, just in case. Do the script run when executed from the command line rather than cron? – EightBitTony Jan 18 at 10:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.