exec cmd: base64 stdout and stderr

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
This commit is contained in:
Jianhui Zhao
2019-01-07 19:47:19 +08:00
parent d273c593c1
commit 80bb133515
4 changed files with 138 additions and 9 deletions

46
tools/sendcmd.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/sh
host=localhost
port=5912
devid="test"
cmd="echo"
params='["hello rtty"]'
username="test"
password="test"
resp=$(curl "http://$host:$port/cmd" -d "{\"devid\":\"$devid\", \"cmd\":\"$cmd\", \"params\": $params, \"username\": \"$username\", \"password\": \"$password\"}" 2>/dev/null)
token=$(echo "$resp" | jq -r '.token')
[ "$token" = "null" ] && {
echo "$resp"
exit 1
}
while [ true ]
do
resp=$(curl "http://$host:$port/cmd?token=$token" 2>/dev/null)
err=$(echo "$resp" | jq -r '.err')
[ "$err" = "1005" ] && {
echo "Pending..."
sleep 1
continue
}
[ -n "err" ] && {
msg=$(echo "$resp" | jq -r '.msg')
echo "err: $err"
echo "msg: $msg"
break
}
code=$(echo "$resp" | jq -r '.code')
stdout=$(echo "$resp" | jq -r '.stdout' | base64 -d)
stderr=$(echo "$resp" | jq -r '.stderr' | base64 -d)
echo "code: $code"
echo "stdout: $stdout"
echo "stderr: $stderr"
break
done