forked from kanthaus/kanthaus.online
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·49 lines (39 loc) · 982 Bytes
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# 1. Runs the grav development server
# 2. gets all available pages from the sitemap
# 3. opens each of them with curl
# If there's any page with status code != 200, this script fails
set -e
cleanup()
{
echo
echo "killing server with PID" "$SERVER_PID"
kill -9 "$SERVER_PID"
}
trap cleanup EXIT
php -S localhost:8000 system/router.php 2> /dev/null &
SERVER_PID=$!
while [[ $(curl -s -o /dev/null -w "%{http_code}" localhost:8000/sitemap) != "200" ]]
do sleep 0.1
done
SITEMAP=$(curl -s http://localhost:8000/sitemap)
URLS=$(sed -n 's/^.*<loc>\(.*\)<\/loc>.*$/\1/p' <<< "${SITEMAP}")
if [[ $URLS != http* ]]; then
echo Invalid sitemap!
echo "$SITEMAP"
exit 1
fi
echo
echo testing "$(wc -l <<< "$URLS")" URLs...
for URL in $URLS
do
CODE=$(curl -s -o /dev/null -w "%{http_code}" "$URL")
if [[ x"$CODE" == x"200" ]]; then
printf "."
else
echo "this url is broken:" "$URL"
exit 1
fi
done
echo
echo Successfully finished.