我在Mac OS上试图通过crontab运行我的程序时遇到了问题。当我的程序独立运行时,它可以正常工作。通常情况下,我从来没有为远程系统密码设置env.password,而是设置env.key_filename。相反,我设置env.key_filename。如果我不需要运行sudo命令,它就能正常工作。所以理想情况下,它不应该提示输入任何密码。
通过参考 https:/github.comfabricfabricissues1230。我也尝试设置环境变量来传递密码。然而,我还是得到同样的错误。我错过了什么?有谁可以帮助我?
谢谢
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getpass.py:83: GetPassWarning: Can not control echo on the terminal.
passwd = fallback_getpass(prompt, stream)
Warning: Password input may be echoed.
[xxx.xxx.xxx.xxx] Login password for 'xxx': [xxx.xxx.xxx.xxx] Executing task 'System.Monitor.free_mem'
[+] Start checking system total/free memory in MB:
[xxx.xxx.xxx.xxx] run: free -m
Traceback (most recent call last):
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/main.py", line 757, in main
*args, **kwargs
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/tasks.py", line 386, in execute
multiprocessing
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/tasks.py", line 276, in _execute
return task.run(*args, **kwargs)
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/tasks.py", line 173, in run
return self.wrapped(*args, **kwargs)
File "/Users/thomas.pan/Python-ninja/playwith/DevOps/System/Monitor.py", line 69, in free_mem
run("free -m")
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/network.py", line 687, in host_prompting_wrapper
return func(*args, **kwargs)
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/operations.py", line 1090, in run
shell_escape=shell_escape, capture_buffer_size=capture_buffer_size,
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/operations.py", line 930, in _run_command
channel=default_channel(), command=wrapped_command, pty=pty,
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/state.py", line 424, in default_channel
chan = _open_session()
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/state.py", line 416, in _open_session
return connections[env.host_string].get_transport().open_session()
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/network.py", line 159, in __getitem__
self.connect(key)
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/network.py", line 151, in connect
user, host, port, cache=self, seek_gateway=seek_gateway)
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/network.py", line 569, in connect
password = prompt_for_password(text)
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/network.py", line 652, in prompt_for_password
new_password = _password_prompt(password_prompt, stream)
File "/usr/local/var/pyenv/versions/2.7.10/lib/python2.7/site-packages/fabric/network.py", line 624, in _password_prompt
return getpass.getpass(prompt.encode('ascii', 'ignore'), stream)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getpass.py", line 83, in unix_getpass
passwd = fallback_getpass(prompt, stream)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getpass.py", line 118, in fallback_getpass
return _raw_input(prompt, stream)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getpass.py", line 135, in _raw_input
raise EOFError
EOFError
用LaunchControl工具切换到Launchd,问题就解决了。这不是Fabric的问题。
万一对任何人都有帮助--如果你运行的命令是登录到一个实例,这个GetPassWarningOEFError问题可能会在cron作业中发生,因为shell会话不知道如何登录到该实例。
要解决这个问题,你可能需要给crond提供ssh上下文。ssh-cron 例如,可以做到这一点,因为看起来在crontab中设置这一切是有困难的。