2017-04-24 71 views
0

我正在嘗試檢查進程是否從UNIX系統主動運行。它可以是一個進程或多個進程。以下是我正在嘗試的示例。有人能指導我如何實現這一目標嗎?如何使用機器人框架檢查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 

[[email protected] 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 
============================================================================== 

回答

2
  1. /etc/init.d/bluetooth是啓動腳本,你會不會來檢查啓動腳本,而是通過它

  2. 關鍵字啓動的進程(ES)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時刻保持運行。

+0

感謝評論,我會盡力回答,我的目的是爲了檢查類似下面'[根@ HY的init.d]#MDB_Platform_PostgreSQL狀態 pg_ctl過程:服務器正在運行(PID:9997)'。我想驗證這個過程是否正在運行,像這樣我有一套要驗證的過程。 – Madhu

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} 
相關問題