这是我的脚本(randomg.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 = []
for root, dirs, files in os.walk(BACKGROUND):
for 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()
我已经运行chmod a+x randombg.py
并且它与. 一起工作python randombg.py
。假设它的路径/path/to/randombg.py.
也是,运行/path/to/randombg.py
工作。
但是,当我将其添加到 crontab 时,如下所示:
1 * * * * /path/to/randombg.py
或者
01 * * * * python /path/to/randombg.py
或者
01 * * * * /usr/bin/python /path/to/randombg.py
都失败了。
我想不通。谁能解释一下?
PS:ArchLinux
更多信息
当我跑步时ps aux|grep python
,我有时会找不到randombg.py
它出现的时间。
来自 crontab 重定向标准错误的附加日志:
import: unable to open X server `' @ error/import.c/ImportImageCommand/361.
import: unable to open X server `' @ error/import.c/ImportImageCommand/361.
import: unable to 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():'