Pipe curl output into double tac to prevent broken pipe

This commit is contained in:
cytopia 2018-12-15 22:58:29 +01:00
parent a652b0d8c5
commit 60b2d99c09
No known key found for this signature in database
GPG Key ID: 6D56EDB8695128A2
5 changed files with 63 additions and 33 deletions

View File

@ -4,6 +4,13 @@ set -e
set -u
set -o pipefail
#
# NOTE: Parsing curl to tac to circumnvent "failed writing body"
# https://stackoverflow.com/questions/16703647/why-curl-return-and-error-23-failed-writing-body
#
NUM_OK="20"
NUM_ERR="0"
@ -14,18 +21,18 @@ NUM_ERR="0"
printf "[TEST] dvlbox-ok"
# 1st Try
TEST_OK="$( curl -sS localhost/index.php | grep -c 'dvlbox-ok' || true )"
TEST_OK="$( curl -sS localhost/index.php | tac | tac | grep -c 'dvlbox-ok' || true )"
if [ "${TEST_OK}" != "${NUM_OK}" ]; then
# 2nd Try
sleep 1
TEST_OK="$( curl -sS localhost/index.php | grep -c 'dvlbox-ok' || true )"
TEST_OK="$( curl -sS localhost/index.php | tac | tac | grep -c 'dvlbox-ok' || true )"
if [ "${TEST_OK}" != "${NUM_OK}" ]; then
# 3rd Try
sleep 1
TEST_OK="$( curl -sS localhost/index.php | grep -c 'dvlbox-ok' || true )"
TEST_OK="$( curl -sS localhost/index.php | tac | tac | grep -c 'dvlbox-ok' || true )"
if [ "${TEST_OK}" != "${NUM_OK}" ]; then
printf "\r[FAIL] dvlbox-ok\n"
curl -sS localhost/index.php | grep -c 'dvlbox-ok' || true
curl -sS localhost/index.php | tac | tac | grep -c 'dvlbox-ok' || true
exit 1
else
printf "\r[OK] dvlbox-ok (3 rounds)\n"
@ -44,18 +51,18 @@ fi
printf "[TEST] dvlbox-err"
# 1st Try
TEST_ERR="$( curl -sS localhost/index.php | grep -c 'dvlbox-err' || true )"
TEST_ERR="$( curl -sS localhost/index.php | tac | tac | grep -c 'dvlbox-err' || true )"
if [ "${TEST_ERR}" != "${NUM_ERR}" ]; then
# 2nd Try
sleep 1
TEST_ERR="$( curl -sS localhost/index.php | grep -c 'dvlbox-err' || true )"
TEST_ERR="$( curl -sS localhost/index.php | tac | tac | grep -c 'dvlbox-err' || true )"
if [ "${TEST_ERR}" != "${NUM_ERR}" ]; then
# 3rd Try
sleep 1
TEST_ERR="$( curl -sS localhost/index.php | grep -c 'dvlbox-err' || true )"
TEST_ERR="$( curl -sS localhost/index.php | tac | tac | grep -c 'dvlbox-err' || true )"
if [ "${TEST_ERR}" != "${NUM_ERR}" ]; then
printf "\r[FAIL] dvlbox-err\n"
curl -sS localhost/index.php | grep -c 'dvlbox-err' || true
curl -sS localhost/index.php | tac | tac | grep -c 'dvlbox-err' || true
exit 1
else
printf "\r[OK] dvlbox-err (3 rounds)\n"

View File

@ -5,13 +5,19 @@ set -u
set -o pipefail
#
# NOTE: Parsing curl to tac to circumnvent "failed writing body"
# https://stackoverflow.com/questions/16703647/why-curl-return-and-error-23-failed-writing-body
#
printf "[TEST] devilbox-version key in Memcached"
# 1st Try
if ! curl -sS localhost/db_memcd.php | grep -q 'devilbox-version'; then
if ! curl -sS localhost/db_memcd.php | tac | tac | grep -q 'devilbox-version'; then
sleep 1
if ! curl -sS localhost/db_memcd.php | grep -q 'devilbox-version'; then
if ! curl -sS localhost/db_memcd.php | tac | tac | grep -q 'devilbox-version'; then
sleep 1
if ! curl -sS localhost/db_memcd.php | grep -q 'devilbox-version'; then
if ! curl -sS localhost/db_memcd.php | tac | tac | grep -q 'devilbox-version'; then
printf "\r[FAIL] devilbox-version key in Memcached\n"
curl -sS localhost/db_memcd.php || true
exit 1

View File

@ -4,14 +4,19 @@ set -e
set -u
set -o pipefail
#
# NOTE: Parsing curl to tac to circumnvent "failed writing body"
# https://stackoverflow.com/questions/16703647/why-curl-return-and-error-23-failed-writing-body
#
printf "[TEST] devilbox-version key in Redis"
# 1st Try
if ! curl -sS localhost/db_redis.php | grep -q 'devilbox-version'; then
if ! curl -sS localhost/db_redis.php | tac | tac | grep -q 'devilbox-version'; then
sleep 1
if ! curl -sS localhost/db_redis.php | grep -q 'devilbox-version'; then
if ! curl -sS localhost/db_redis.php | tac | tac | grep -q 'devilbox-version'; then
sleep 1
if ! curl -sS localhost/db_redis.php | grep -q 'devilbox-version'; then
if ! curl -sS localhost/db_redis.php | tac | tac | grep -q 'devilbox-version'; then
printf "\r[FAIL] devilbox-version key in Redis\n"
curl -sS localhost/db_redis.php || true
exit 1

View File

@ -5,21 +5,27 @@ set -u
set -o pipefail
#
# NOTE: Parsing curl to tac to circumnvent "failed writing body"
# https://stackoverflow.com/questions/16703647/why-curl-return-and-error-23-failed-writing-body
#
###
### Retrieve URL for current Adminer version.
###
printf "[TEST] Retrieve Adminer URL"
# 1st Try
if ! URL="$( curl -sS localhost/index.php | grep -Eo "/vendor/adminer-[.0-9]+-en\.php" )"; then
if ! URL="$( curl -sS localhost/index.php | tac | tac | grep -Eo "/vendor/adminer-[.0-9]+-en\.php" )"; then
# 2nd Try
sleep 1
if ! URL="$( curl -sS localhost/index.php | grep -Eo "/vendor/adminer-[.0-9]+-en\.php" )"; then
if ! URL="$( curl -sS localhost/index.php | tac | tac | grep -Eo "/vendor/adminer-[.0-9]+-en\.php" )"; then
# 3rd Try
sleep 1
if ! URL="$( curl -sS localhost/index.php | grep -Eo "/vendor/adminer-[.0-9]+-en\.php" )"; then
if ! URL="$( curl -sS localhost/index.php | tac | tac | grep -Eo "/vendor/adminer-[.0-9]+-en\.php" )"; then
printf "\r[FAILED] Retrieve Adminer URL\n"
curl -sS localhost/index.php | grep -Eo "/vendor/adminer-[.0-9]+-en\.php" || true
curl -sS localhost/index.php | tac | tac | grep -Eo "/vendor/adminer-[.0-9]+-en\.php" || true
exit 1
else
printf "\r[OK] Retrieve Adminer URL (3 rounds): ${URL}\n"
@ -38,13 +44,13 @@ fi
printf "[TEST] Fetch ${URL}"
# 1st Try
if ! curl -sS localhost${URL} | grep -Eiq "Login.+Adminer"; then
if ! curl -sS localhost${URL} | tac | tac | grep -Eiq "Login.+Adminer"; then
# 2nd Try
sleep 1
if ! curl -sS localhost${URL} | grep -Eiq "Login.+Adminer"; then
if ! curl -sS localhost${URL} | tac | tac | grep -Eiq "Login.+Adminer"; then
# 3rd Try
sleep 1
if ! curl -sS localhost${URL} | grep -Eiq "Login.+Adminer"; then
if ! curl -sS localhost${URL} | tac | tac | grep -Eiq "Login.+Adminer"; then
printf "\r[FAIL] Fetch ${URL}\n"
curl -sS localhost${URL} || true
curl -sSI localhost${URL} || true
@ -66,13 +72,13 @@ fi
printf "[TEST] Adminer MySQL login"
# 1st Try
if ! curl -sS "localhost${URL}?server=127.0.0.1&username=root" | grep -Eiq "Database.+Collation.+Tables"; then
if ! curl -sS "localhost${URL}?server=127.0.0.1&username=root" | tac | tac | grep -Eiq "Database.+Collation.+Tables"; then
# 2nd Try
sleep 1
if ! curl -sS "localhost${URL}?server=127.0.0.1&username=root" | grep -Eiq "Database.+Collation.+Tables"; then
if ! curl -sS "localhost${URL}?server=127.0.0.1&username=root" | tac | tac | grep -Eiq "Database.+Collation.+Tables"; then
# 3rd Try
sleep 1
if ! curl -sS "localhost${URL}?server=127.0.0.1&username=root" | grep -Eiq "Database.+Collation.+Tables"; then
if ! curl -sS "localhost${URL}?server=127.0.0.1&username=root" | tac | tac | grep -Eiq "Database.+Collation.+Tables"; then
printf "\r[FAIL] Adminer MySQL login\n"
curl -sS "localhost${URL}?server=127.0.0.1&username=root" || true
curl -sSI "localhost${URL}?server=127.0.0.1&username=root" || true
@ -94,13 +100,13 @@ fi
printf "[TEST] Adminer PgSQL login"
# 1st Try
if ! curl -sS "localhost${URL}?pgsql=127.0.0.1&username=postgres" | grep -Eiq "Database.+Collation.+Tables"; then
if ! curl -sS "localhost${URL}?pgsql=127.0.0.1&username=postgres" | tac | tac | grep -Eiq "Database.+Collation.+Tables"; then
# 2nd Try
sleep 1
if ! curl -sS "localhost${URL}?pgsql=127.0.0.1&username=postgres" | grep -Eiq "Database.+Collation.+Tables"; then
if ! curl -sS "localhost${URL}?pgsql=127.0.0.1&username=postgres" | tac | tac | grep -Eiq "Database.+Collation.+Tables"; then
# 3rd Try
sleep 1
if ! curl -sS "localhost${URL}?pgsql=127.0.0.1&username=postgres" | grep -Eiq "Database.+Collation.+Tables"; then
if ! curl -sS "localhost${URL}?pgsql=127.0.0.1&username=postgres" | tac | tac | grep -Eiq "Database.+Collation.+Tables"; then
printf "\r[FAIL] Adminer PgSQL login\n"
curl -sS "localhost${URL}?pgsql=127.0.0.1&username=postgres" || true
curl -sSI "localhost${URL}?pgsql=127.0.0.1&username=postgres" || true
@ -122,13 +128,13 @@ fi
printf "[TEST] Adminer Mongo login"
# 1st Try
if ! curl -sS "localhost${URL}?mongo=127.0.0.1&username=" | grep -Eiq "Database.+Collation.+Tables"; then
if ! curl -sS "localhost${URL}?mongo=127.0.0.1&username=" | tac | tac | grep -Eiq "Database.+Collation.+Tables"; then
# 2nd Try
sleep 1
if ! curl -sS "localhost${URL}?mongo=127.0.0.1&username=" | grep -Eiq "Database.+Collation.+Tables"; then
if ! curl -sS "localhost${URL}?mongo=127.0.0.1&username=" | tac | tac | grep -Eiq "Database.+Collation.+Tables"; then
# 3rd Try
sleep 1
if ! curl -sS "localhost${URL}?mongo=127.0.0.1&username=" | grep -Eiq "Database.+Collation.+Tables"; then
if ! curl -sS "localhost${URL}?mongo=127.0.0.1&username=" | tac | tac | grep -Eiq "Database.+Collation.+Tables"; then
printf "\r[FAIL] Adminer Mongo login\n"
curl -sS "localhost${URL}?mongo=127.0.0.1&username=" || true
curl -sSI "localhost${URL}?mongo=127.0.0.1&username=" || true

View File

@ -5,6 +5,12 @@ set -u
set -o pipefail
#
# NOTE: Parsing curl to tac to circumnvent "failed writing body"
# https://stackoverflow.com/questions/16703647/why-curl-return-and-error-23-failed-writing-body
#
###
### Retrieve URL for current PHP version.
### Older PHP versions are presented a link with a different version due to compatibility.
@ -39,13 +45,13 @@ fi
printf "[TEST] Fetch ${URL}"
# 1st Try
if ! curl -sS localhost${URL} | grep -Eiq "welcome to.+phpMyAdmin"; then
if ! curl -sS localhost${URL} | tac | tac | grep -Eiq "welcome to.+phpMyAdmin"; then
# 2nd Try
sleep 1
if ! curl -sS localhost${URL} | grep -Eiq "welcome to.+phpMyAdmin"; then
if ! curl -sS localhost${URL} | tac | tac | grep -Eiq "welcome to.+phpMyAdmin"; then
# 3rd Try
sleep 1
if ! curl -sS localhost${URL} | grep -Eiq "welcome to.+phpMyAdmin"; then
if ! curl -sS localhost${URL} | tac | tac | grep -Eiq "welcome to.+phpMyAdmin"; then
printf "\r[FAIL] Fetch ${URL}\n"
curl -sS localhost/${URL} || true
curl -sSI localhost/${URL} || true