Difference between revisions of "Curl bash script"
Jump to navigation
Jump to search
(Created page with "#!/bin/bash set -eu mcode=200 url="https://example.com" while true; do ts=$(date "+%Y%m%dT%H%M%S") rcode=$(curl -X GET -sI "$url" | awk '/^HTTP/{print $2}') if [ "$rco...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | ## Test return code | ||
+ | ``` | ||
#!/bin/bash | #!/bin/bash | ||
set -eu | set -eu | ||
− | + | expected_rcode=200 | |
url="https://example.com" | url="https://example.com" | ||
Line 8: | Line 10: | ||
ts=$(date "+%Y%m%dT%H%M%S") | ts=$(date "+%Y%m%dT%H%M%S") | ||
rcode=$(curl -X GET -sI "$url" | awk '/^HTTP/{print $2}') | rcode=$(curl -X GET -sI "$url" | awk '/^HTTP/{print $2}') | ||
− | if [ "$rcode" != "$ | + | if [ "$rcode" != "$expected_rcode" ]; then |
− | echo "ERROR: Invalid code. Was $rcode expected $ | + | echo "ERROR: Invalid code. Was $rcode expected $expected_rcode. TS: $ts" |
fi | fi | ||
sleep 5 | sleep 5 | ||
done | done | ||
+ | ``` |
Latest revision as of 00:40, 26 September 2023
Test return code
#!/bin/bash set -eu expected_rcode=200 url="https://example.com" while true; do ts=$(date "+%Y%m%dT%H%M%S") rcode=$(curl -X GET -sI "$url" | awk '/^HTTP/{print $2}') if [ "$rcode" != "$expected_rcode" ]; then echo "ERROR: Invalid code. Was $rcode expected $expected_rcode. TS: $ts" fi sleep 5 done