Python Fabric:如何在屏幕会话中执行命令

时间:2017-05-10 14:41:30

标签: python fabric devops gnu-screen

我正在做以下事情:

with settings(host_string=h['server'].rstrip('\n').strip(), warn_only=True):
                # run("hostname -f")
                with cd('path/folder'):
                  # Check for Screen session, if none, create one otherwise screen -d -r
                    result = run('screen -r')
                    output_stdout = result.stdout.strip()
                    print('OUTPUT = ' + output_stdout)
                    if 'There is a screen on' in output_stdout:
                        run('screen -d -r')
                        run('exit')
                    elif 'There is no screen to be resumed' in output_stdout:
                        run('screen')
                        # Checking screen stats
                        run('screen -r')
                       # Generate Link File
                       run('python3 file.py ' + str(start) + ' ' + str(end))

当屏幕打开时,织物进入无限循环并且永远不会出现。

1 个答案:

答案 0 :(得分:2)

您是否尝试过screen -Rd

-d -R   Reattach a session and if necessary detach or even create it first.