forked from lromang/URLs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_test.sh
executable file
·34 lines (26 loc) · 957 Bytes
/
url_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
#!/bin/bash
for i in $(seq `tail -n +2 urls.psv | wc -l`)
do
# Get row
row=$(tail -n +2 urls.psv |awk 'FNR == "'"$i"'" {print}' | sed 's/"//g')
# Get data
dep=$(echo $row | cut -d "|" -f1)
slug=$(echo $row | cut -d "|" -f2)
rec=$(echo $row | cut -d "|" -f3)
url=$(echo $row | cut -d "|" -f4)
# Time prior URL verification.
T="$(date +%s)"
# URL verification.
urlstatus=$(timeout $1s curl -k -o /dev/null --silent --head --write-out '%{http_code}' "$url" )
# Verification time.
T="$(($(date +%s)-T))"
# Check if timeout.
if [ $(echo $urlstatus | wc -m) -eq 1 ]
then
urlstatus="time_out"
fi
# Print results.
echo "dep: $dep | slug: $slug | rec: $rec | url: $url | status: $urlstatus | execution time: $T | date: `date`"
# Send results to file.
echo -e "$dep \t $slug \t $rec \t $url \t $urlstatus \t $T \t `date`" >> urlstatus.csv
done