在crontab中运行Python Fabric命令时,可以回显密码输入

时间:2017-08-15 11:04:02

标签: python python-2.7 fabric

尝试在Mac OS上通过crontab运行程序时遇到问题。我的程序在独立运行时工作正常。通常,我从不为远程系统密码设置env.password。相反,我设置了env.key_filename。如果我不必运行sudo命令,它工作正常。理想情况下,它不应该提示任何密码输入。

通过引用https://github.com/fabric/fabric/issues/1230,我还尝试设置环境变量来传递密码。然而,我仍然得到同样的错误。我错过了什么?任何人都可以帮忙吗?

THX

错误消息:

/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

2 个答案:

答案 0 :(得分:0)

通过使用LaunchControl工具切换到launchd来关闭问题。它不是Fabric问题。

答案 1 :(得分:0)

万一它对任何人都有帮助-如果您正在运行登录到实例的命令,则cron作业可能会发生此GetPassWarning / OEFError问题,因为shell会话不知道如何登录该实例。 / p>

要解决此问题,您可能需要为crond提供ssh上下文。例如,ssh-cron可以做到这一点,因为似乎很难在crontab中进行全部设置。