linux - Python script runs in bash, but not in cron? -


i have written python script goes reddit (using praw), goes specific subreddit, , downloads episodes of podcast youtube using youtube-dl. placed script in /bin folder, can run anywhere bash. problem runs fine in bash, not in cron @ all. i've set in cron this:

0 */1 * * * pka.py 

here copy of stacktrace cron puts in /var/mail:

traceback (most recent call last):      file "/bin/pka.py", line 48, in <module>     call(mycall)   file "/usr/lib/python2.7/subprocess.py", line 522, in call     return popen(*popenargs, **kwargs).wait()   file "/usr/lib/python2.7/subprocess.py", line 710, in __init__     errread, errwrite)   file "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child     raise child_exception oserror: [errno 2] no such file or directory 

the crash happens @ system call. gives error 'no such file or directory', of directories correct. i'm using absolute paths, shouldn't problem. i'm having hard time figuring out problem, , i'd appreciate guys give. here full script:

#!/usr/bin/env python import praw import os subprocess import call  #directories pka_dir = '/home/chris/storage/750g/pka/' pka_downloaded = '/home/chris/storage/750g/pka/pka-downloaded' pkn_dir = '/home/chris/storage/750g/pkn/' pkn_downloaded = '/home/chris/storage/750g/pkn/pkn-downloaded'  #create reddit instance reddit = praw.reddit(deleted privacy) subreddit = reddit.subreddit(deleted subreddit name)  submission in subreddit.new(limit=5):     isdownloaded = false     open(pkn_downloaded, 'r') downloaded:         line in downloaded:             if submission.url in line:                 isdownloaded = true             if line in submission.url:                 isdownloaded = true         if isdownloaded == false:             title, episode = submission.title.split()             if title == 'pkn':                 mytitle = 'pkn #%s'%(episode) + '.%(ext)s'                 mycall = ['youtube-dl', '-f ' 'bestvideo[ext=mp4]+bestaudio[ext=m4a]', '-o' '%s%s'%(pkn_dir,mytitle), submission.url]                 call(mycall)                 open(pkn_downloaded, 'a') writeout:                     writeout.write(submission.url + '\n')     isdownloaded = false     open(pka_downloaded, 'r') downloaded:         line in downloaded:             if submission.url in line:                 isdownloaded = true             if line in submission.url:                 isdownloaded = true         if isdownloaded == false:             title, episode = submission.title.split()             if title == 'pka':                 mytitle = 'pka #%s - '%(episode) + '%(title)s.%(ext)s'                 mycall = ['youtube-dl', '-f ' 'bestvideo[ext=mp4]+bestaudio[ext=m4a]', '-o' '%s%s'%(pka_dir,mytitle), submission.url]                 call(mycall)                 open(pka_downloaded, 'a') writeout:                     writeout.write(submission.url + '\n') 

the programs signs bots account (i know isn't necessary, wanted try out full features of praw), , navigates subreddit. considers recent 5 posts, , pulls youtube link it. checks link against text file database of downloaded episodes. if episode has not been downloaded, downloads , adds list. puts necessary arguments list, , system call call. suspected issue due permissions, searching has told me cron runs jobs root. folder it's downloading (`/home/chris/storage/750g') on seperate drives, that's why thought permissions might have been problem.

any suggestions?

the simplest solution use full absolute path youtube-dl. in case, use /usr/local/bin/youtube-dl instead of youtube-dl.

the reason:

some linux distributions, ubuntu, changes original path variable include commands in /usr/local/bin when user accessed shell. however, cron passes minimal set of environment variables job , keeps original path[1].


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -