تمرين إعادة البناء
URL Health Checker
أعد كتابة سكربت Bash يستخدم curl لفحص قائمة روابط وطباعة أكواد الاستجابة.
bash
~12 دقيقة
متوسط
أعد بناء الكود
Rebuild
هذا هو الكود. اكتبه بنفسك.
الكود المرجعي
#!/usr/bin/env bash
set -euo pipefail
urls=(
"https://learn.azizwares.sa"
"https://azizwares.sa"
"https://example.com"
)
if ! command -v curl >/dev/null 2>&1; then
printf 'curl is required for this script.\n' >&2
exit 1
fi
for url in "${urls[@]}"; do
status=$(curl -L -o /dev/null -s -w '%{http_code}' --max-time 5 "$url" || true)
printf '%-32s %s\n' "$url" "$status"
doneاكتب هنا