Reputation: 1008
I want to load a file from a clients webserver. This webserver is running local only. To get there I have to use ssh. I need the content as well as the return value (e.g. SSH connection broke, webserver down).
What do I have to change? My first try:
#!/bin/bash
RETURN=0
CONTENT=""
sshpass -p xxxxxx ssh [email protected] "curl -X POST http://127.0.0.1:10000/status -H 'Content-Type: application/json' > $CONTENT | bash; RETURN=$?"
Upvotes: 1
Views: 27965
Reputation: 686
If you want to get the exit code of curl
and the return value of curl
:
#!/bin/bash
CONTENT=$(sshpass -p xxxxxx ssh [email protected] "curl -X POST http://127.0.0.1:10000/status -H 'Content-Type: application/json'")
RETURN=$?
echo "$RETURN, $CONTENT"
In your script you set the variables on the server you ssh'ed into.
Upvotes: 3