cron - Python script not work in crontab -
here script(randombg.py):
#!/usr/bin/env python  # -*- coding: utf8 -*-  import random import subprocess import os    background = '/home/david/wallpaper/dell2312' ignore_files = ['/home/david/wallpaper/dell2312/.directory']   def enumerate():     global background     file_collections = []     root, dirs, files in os.walk(background):         file in files:             file_collections.append(os.path.join(root, file))     return file_collections   def randombg():     select_files = list(set(enumerate())-set(ignore_files))     subprocess.call(['feh', '--bg-scale', random.choice(select_files)])   def main():     while 1:         randombg()   if __name__ == '__main__':     main() i have run chmod a+x randombg.py , worked python randombg.py .let's path /path/to/randombg.py. also, run /path/to/randombg.py worked. 
however, when added crontab below:
1 * * * * /path/to/randombg.py  or
01 * * * * python /path/to/randombg.py or
01 * * * * /usr/bin/python /path/to/randombg.py all failed.
i can't figure out. explain?
ps: archlinux
more infomation
when run ps aux|grep python, can't find  randombg.py while appears.
addtional logs crontab redirect stderr:
import: unable open x server `' @   error/import.c/importimagecommand/361. import: unable open x server `' @ error/import.c/importimagecommand/361. import: unable open x server `' @ error/import.c/importimagecommand/361. /home/david/dotfiles/randombg.py: line 9: background: command not found /home/david/dotfiles/randombg.py: line 10: ignore_files: command not found /home/david/dotfiles/randombg.py: line 13: syntax error near unexpected token `(' /home/david/dotfiles/randombg.py: line 13: `    def enumerate():' 
try change subprocess.call 
subprocess.call("export display=:0; feh --bg-scale " + random.choice(select_files), shell=true) this should export display variable, scripts run crontab not have access environmental variables default.
Comments
Post a Comment