-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkCheckNGrabWRegex.sh
57 lines (54 loc) · 1.84 KB
/
LinkCheckNGrabWRegex.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
50
51
52
53
54
55
56
57
###################################
# 08/06/2018 - Michael Hammond #
# Automated Link Check-n-Grab #
# LinkCheckNGrabWRegex.sh #
# #
# This script feeds redirects #
# from a file to the curl CMD #
# browser in a loop and stores #
# the results of the source #
# URLs provided in a csv file. #
# #
# The Linux machine running #
# this must have cut, and the #
# curl cmd browser installed. #
# #
# For more information, refer #
# to the attached README #
# document. #
###################################
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
less -FX "README.txt" # display README for help.
exit 0
fi
fi
readonly prefix="RedirectMatch 301 "
# Save the prefix as a variable to be stripped.
# the prefix is readonly since it's never written to.
readonly URL="https://www.google.com"
# This readonly variable is the variable used to let the program
# know what domain to start from.
while IFS='' read -r line; do #while hasnextline
{
direct=${line#"$prefix"}
# save next line stripped of prefix
source="$(cut -d' ' -f1 <<< $direct)"
# get part 1 of stripped next line, save as source
dest="$(cut -d' ' -f2 <<< $direct)"
# get part 2 of stripped next line, save as destination
path=$(curl -Ls -o /dev/null -w %{url_effective} "$URL$source")
echo $path
# paste url to variable
if [[ "$path" = "$URL$dest" ]]; then # If the URLs are an exact match
{
echo "$URL$source, $URL$dest, " >> "/outfiles/result-match.csv"
}
else
{
echo "$URL$source, $URL$dest, $path" >> "/outfiles/result-match.csv"
}
fi;
sleep 5
# sleep to give curl time to reload.
}
done < "configmatch.txt" # file to loop through