Zeinab Abbasimazar
Zeinab Abbasimazar

Reputation: 10439

executing command via ssh library in robotframework

executing command via ssh library in robotframework

I'm using robotframework to connect to a remote server and start an application there. I use these keywords:

Create SSH Link
    Open Connection     ${Ip}
    Login               ${Username}     ${Password}

Start Service
    ${cmd} =    "cd " + ${appAddr} + "; ./" + ${appName} + " " + ${appInputArg} + " > /tmp/" + ${appName} "-out.log 2>&1"
    log to console      Going to run command: ${cmd}
    execute command     ${cmd}
    log to console      \nConnected Successfully

Run App
    ${cmd} =    "netstat -putan | grep LISTEN | grep 8898 | awk '{print $7}' | cut -d '/' -f 1"
    ${stdout} =     execute command     ${cmd}
    Run Keyword If          ${stdout} == ${EMPTY}       log to console      \nCommand ${cmd} retruned Error
    Run Keyword Unless      ${stdout} == ${EMPTY}       Start Service    

And this is my test case:

Test Connecting to Remote Server
    Create SSH Link
    Run App

And Output:

==============================================================================
Scenarios                                                                     
==============================================================================
Scenarios.Test :: First Test                                                  
==============================================================================
Test Connecting to Remote Server                                      
Connected Successfully
| FAIL |
No keyword with name '"netstat -putan | grep LISTEN | grep 8898 | awk '{print $7}' | cut -d '/' -f 1"' found.
------------------------------------------------------------------------------
Scenarios.Test :: First Test                                          | PASS |
0 critical tests, 0 passed, 0 failed
1 test total, 0 passed, 1 failed
==============================================================================
Scenarios                                                             | PASS |
0 critical tests, 0 passed, 0 failed
1 test total, 0 passed, 1 failed
==============================================================================

Why it's not going to execute this command on the remote server and searching for a keyword??

Upvotes: 0

Views: 12762

Answers (1)

Laurent Bristiel
Laurent Bristiel

Reputation: 6935

The problem lies in this statement:

${cmd} =    "netstat -putan | grep LISTEN | grep 8898 | awk '{print $7}' | cut -d '/' -f 1"

This is not a valid Robot Framework Statement. Robot Framework is looking for a keyword and can not find any in this statement.

It should be changed into:

${cmd} =    set variable    netstat -putan | grep LISTEN | grep 8898 | awk '{print $7}' | cut -d '/' -f 1

Note: no need for double quotes around your string. By default variables are string in Robot.

Upvotes: 2

Related Questions