Forum Discussion

apresti12's avatar
apresti12
Icon for Nimbostratus rankNimbostratus
Feb 28, 2017

500 Error When Posting Bash Command - PowerShell

Does anyone know why a multi argument bash command fails but a single argument command does not fail? It almost acts as if the "md5sum" command in this example is ran without taking into consideration the filepath.

 

$basicAuthValue = "Basic $base64"
$headers = @{ Authorization = $basicAuthValue }
$Contenttype = "application/json"
$Body = '{
            "kind": "tm:util:bash:runstate",
            "command":"run",
            "utilCmdArgs":"-c md5sum /shared/images/IMAGENAME"
         }'

Invoke-RestMethod -Header $headers -Uri https://localhost/mgmt/tm/util/bash -ContentType $Contenttype -Method Post -Body $Body | format-table -Wrap

This code will result in a 500 error, however, if I change the utilCmdArgs to a command such as "pwd" it succeeds.

 

kind                  command utilCmdArgs commandResult     
----                  ------- ----------- -------------     
tm:util:bash:runstate run     -c pwd      /var/service/icrd 

Has anyone experienced this before or ran into a similar issue?

 

1 Reply

  • This one works for me:

    [nielsvs@localhost ~]$ curl -sk -u apiuser:secret -H 'Content-Type: application/json' -X POST -d '{"command": "run", "utilCmdArgs": "-c \"md5sum /shared/images/BIGIP-13.0.0.0.0.1645.iso\""}' https://10.23.92.5/mgmt/tm/util/bash | jq
    {
    "kind": "tm:util:bash:runstate",
    "command": "run",
    "utilCmdArgs": "-c \"md5sum /shared/images/BIGIP-13.0.0.0.0.1645.iso\"",
    "commandResult": "70c21457c96b8a1381a0efc62fcb94f2  /shared/images/BIGIP-13.0.0.0.0.1645.iso\n"
    }
    [nielsvs@localhost ~]$
    

    Maybe you should use the extra quotes when using the '-c'?