我在 macOS (crontab) 中运行 duplicity 时遇到错误
duplicity 命令如下(在命令行中有效)
/usr/local/bin/duplicity /Users/myname/go file:///Volumes/EVO840\ -\ IMPORTANT/DuplicityGo/ --exclude '**/bin/***' --exclude '**/pkg'
使用时crontab -e
(带或不带 sudo),
* * * * * /Users/myname/bashscripts/duplicity.sh > /Users/myname/bashscripts/duplicity.log 2>&1
它返回以下错误
Traceback (innermost last):
File "/usr/local/bin/duplicity", line 87, in <module>
with_tempdir(main)
File "/usr/local/bin/duplicity", line 72, in with_tempdir
tempdir.default().cleanup()
File "/usr/local/Cellar/duplicity/0.8.23/libexec/lib/python3.9/site-packages/duplicity/tempdir.py", line 69, in default
_defaultInstance = TemporaryDirectory(temproot=config.temproot)
File "/usr/local/Cellar/duplicity/0.8.23/libexec/lib/python3.9/site-packages/duplicity/tempdir.py", line 155, in __init__
temproot = subprocess.check_output([u'getconf', u'DARWIN_USER_TEMP_DIR'])
File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'getconf'
Attempt of list Nr. 1 failed. PermissionError: Operation not permitted
Attempt of list Nr. 3 failed. PermissionError: Operation not permitted
Attempt of list Nr. 4 failed. PermissionError: Operation not permitted
答案1
cron 通常没有或仅设置了有限的 PATH 环境变量。将其设置在 crontab 之上,设置为与在命令行中使用的相同值,错误可能会消失。
答案2
我发现问题出在我使用可移除卷作为欺骗的目的地。
为了使我的 bash 脚本正常工作(或者只是在 crontab 中运行 duplicity),我必须将 /bin/bash 添加到“完全磁盘访问”(不过,我觉得这不安全)