我正在尝试检查进程是否正在从unix系统中主动运行。它可以是一个进程或多个进程。以下是我正在尝试的示例。有人可以指导我如何实现这一目标吗?
*** Settings ***
Library Process
Library OperatingSystem
*** Test cases ***
Example
${output} = Run process /etc/init.d/bluetooth
${op}= Is Process Running ${output}
Should be equal ${op} True
[root@test ssh-scripts]# pybot test-process.robot
==============================================================================
Test-Process
==============================================================================
Example | FAIL |
Non-existing index or alias '<result object with rc 3>'.
------------------------------------------------------------------------------
Test-Process | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
答案 0 :(得分:2)
/etc/init.d/bluetooth
是启动脚本,您不会检查启动脚本,而是检查由它启动的进程
关键字Run Process
等待,直到流程终止。您可能不会等待终止,而是希望在后台运行该过程。
这对我有用:
Test Processes
${handle} Start Process echo foo stdout=/tmp/bar
${output} Is Process Running handle=${handle}
Should Not Be True ${output}
${handle} Start Process yes stdout=/dev/null
${output} Is Process Running handle=${handle}
Should Be True ${output}
[Teardown] Terminate All Processes
即。 echo
在执行第一次Is Process Running
检查之前终止。但yes
已启动,并在第二个Is Process Running
时刻继续运行。
答案 1 :(得分:0)
以下脚本为我工作。在执行命令后,我已经放置了一个正则表达式模式来匹配字符串。这可以通过其他方式实现,但这符合我的目的。
*** Settings ***
Library Process
Library SSHLibrary
Suite Setup Open Connection And Log In
Suite Teardown Close All Connections
Library OperatingSystem
*** Variables ***
${HOST} 16.10.90.24
${USERNAME} root
${PASSWORD} admin123
${postgres_cmd} /etc/init.d/DB_Platform_TaskManager status
${PATTERN} (?m).*is\ running
*** Test Cases ***
Check whether postgres is running
Open Connection And Log In
Start Command ${postgres_cmd}
${rc}= Read Command Output return_stdout=True return_rc=False
Log ${rc}
Should Match Regexp ${rc} ${PATTERN}
*** Keywords ***
Open Connection And Log In
Open Connection ${HOST}
Login ${USERNAME} ${PASSWORD}