-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbatch.sh
executable file
·64 lines (51 loc) · 1.59 KB
/
batch.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
#!/bin/bash
# Output constants
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
NC='\033[0m'
FAIL="${RED}FAIL: ${NC}"
ERROR="${RED}ERROR: ${NC}"
PASS="${GREEN}PASS: ${NC}"
INFO="${BLUE}INFO: ${NC}"
UNKNOWN="${YELLOW}UNKNOWN: ${NC}"
pushd `dirname $0` > /dev/null
SCRIPTPATH=`pwd`
popd > /dev/null
# Default settings
COLUMN=1
CONCURRENCY=8
ORDER=""
HELP=$(cat <<EOF
This script is used to batch call the check script in this package. It is
intended to be passed a csv file of URLs/paths to check.
Usage: ${0} [OPTIONS] CSVFILE
Where CSVFILE is a CSV file containing a column of URLs to check.
-f: Indicate which column in the csv contains the URLs to check. Default ${COLUMN}
-c: Indicates how many concurrent connections. Default ${CONCURRENCY}
-k: Keep same order. Default no
-h: This help message and exit.
Note that this script requires parallel, and awk.
EOF
)
options='c:f:hk'
while getopts $options option; do
case "${option}" in
c) CONCURRENCY=${OPTARG};;
f) COLUMN=${OPTARG};;
h) echo "${HELP}"; exit 0;;
k) ORDER="-k";;
:) echo "${HELP}"; echo "Missing option argument for -${option}" >&2; exit 1;;
*) echo "${HELP}"; echo -e "${ERROR}Unexpected option ${option}"; exit 1;;
esac
done
shift $(($OPTIND - 1))
# Check that we got one remaining parameter the path/url.
if [[ -d $1 ]]; then
echo -e "${ERROR}You must supply a valid csv file to check. eg. ${0} urls.csv"
exit 1;
fi
# Strip leading, trailing quotes and spaces and remove http(s):// if present.
csvfile=$1
parallel -j${CONCURRENCY} ${ORDER} -a ${csvfile} "${SCRIPTPATH}/shim.sh ${COLUMN}"