-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl-process.sh
executable file
·75 lines (55 loc) · 1.21 KB
/
url-process.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
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Generalizable option handler
while getopts ":cgrh" opt; do
case ${opt} in
c ) # process option c
myOpt=checkURLs
echo "Check URLs"
;;
g ) # process option g
myOpt=grepURLs
echo "Grep URLs"
;;
r ) # process option r
myOpt=getRedirects
echo "Get Redirects"
;;
h ) # process option h
myOpt=helpMe
echo "Help me!"
;;
\? ) echo "Usage: cmd [-c] [-g] [-r] [-h] <URL file> <optional grep pattern>"
;;
esac
done
URLfile="$2"
grepPattern="$3"
theURLs=( "$(cat $URLfile)" )
delimiter=" : "
# need more error handling!
case "$myOpt" in
checkURLs)
# process URL header info (http response code)
for i in ${theURLs[@]}
do
echo -n $i $delimiter `curl --progress-bar -I -X GET $i | head -n 1 | cut -d$' ' -f2`
echo ""
done
;;
grepURLs)
# process URL grep
#to do: add error for no grep string
for i in ${theURLs[@]}
do
echo -n $i $delimiter `curl --progress-bar -s $i | grep $grepPattern`
echo ""
done
;;
getRedirects)
# process URL headers and return Location
for i in ${theURLs[@]}
do
echo -n $i $delimiter `curl --progress-bar -I -X GET $i | grep -Fi Location`
echo ""
done
esac