V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
pythonee
V2EX  ›  Python

fabric能获取run的结果吗?

  •  
  •   pythonee · 2013-08-22 18:35:20 +08:00 · 7341 次点击
    这是一个创建于 3910 天前的主题,其中的信息可能已经有所发展或是发生改变。
    发现很多东西需要依赖远程命令的结果做相应的操作,但是fabric没有返回远程结果的样子,google搜了一下,没有什么好的办法。所以也想看看各位有没有好的变通方法。

    deploy包含T1, T2, T3三个人物,他们是有顺序依赖的,也即是T1必须先启动,然后才能T2,最后T3

    T1,T2,T3都是daemon式的程序,如果重定向输出的话,那么就只能通过检测端口或输出来判断是否已经启动成功,比如我想检测web server是否成功,就需要fabric run('netstat -tpln |grep 8080')来判断,可是fabric没有获取执行结果的功能啊。如果不用重定向的话,fabric就会停在T1处
    11 条回复    1970-01-01 08:00:00 +08:00
    ipconfiger
        1
    ipconfiger  
       2013-08-22 18:41:19 +08:00
    可以获取结果啊,就是重定向
    dreampuf
        2
    dreampuf  
       2013-08-22 19:35:58 +08:00
    手工判断吧,还只是 on roadmap
    https://github.com/fabric/fabric/issues/452

    run调用的结果就是stdout
    ry_wang
        3
    ry_wang  
       2013-08-23 08:13:42 +08:00 via iPad
    pythonee
        4
    pythonee  
    OP
       2013-08-23 09:10:19 +08:00
    @dreampuf 这还是不好使,手工判断需要传参给脚本。

    这么说吧,我们用fabric判断远程每个端口已经打开
    pythonee
        5
    pythonee  
    OP
       2013-08-23 09:10:30 +08:00
    @pythonee 某个
    dreampuf
        6
    dreampuf  
       2013-08-23 11:56:08 +08:00
    @pythonee 。。。手工判断不是真让你手工输入判断。。。是让你写code去检查

    ret = run("netstat -tlnp | grep 80")
    if ret:
    BLAHBLAHBLAH
    pythonee
        7
    pythonee  
    OP
       2013-08-24 10:48:06 +08:00
    @dreampuf 关键是这个ret你是永远拿不到的啊,问题就是这个啊,如果我能获取结果,那我就不问了呀
    dreampuf
        8
    dreampuf  
       2013-08-24 21:57:49 +08:00
    @pythonee 为什么拿不到?
    pythonee
        9
    pythonee  
    OP
       2013-08-25 01:03:57 +08:00
    @dreampuf fabric不支持run返回结果吧
    dreampuf
        10
    dreampuf  
       2013-08-25 11:52:11 +08:00
    @pythonee 为什么你不自己试一下?

    (g)$:~/fortest$ fab -u XX test:hosts=XXX
    [tucao.in] Executing task 'test'
    WARNING: IPython History requires SQLite, your history will not be saved
    WARNING: IPython History requires SQLite, your history will not be saved
    --Return--
    None
    > ~/fabfile.py(6)test()
    5 def test():
    ----> 6 import ipdb; ipdb.set_trace()
    7

    ipdb> ret = run("ls")
    [tucao.in] run: ls
    [tucao.in] out: hub net_status.sh nginx.conf opt sslkey tmp www youtube-dl
    [tucao.in] out:

    ipdb> ret
    'hub net_status.sh nginx.conf opt sslkey tmp www\tyoutube-dl'
    ipdb>
    Exiting Debugger.
    Disconnecting from XXX... done.
    pythonee
        11
    pythonee  
    OP
       2013-08-25 13:00:27 +08:00
    @dreampuf 咦,我是跑了一次,然后特别在程序里用 print 来看看有没有,结果发现不能获得结果才发问的,一定是我打开的方式不对,或是版本不对,回头我测试一下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1481 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 17:07 · PVG 01:07 · LAX 10:07 · JFK 13:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.