mirror of
https://github.com/letic/Shell-Scripts.git
synced 2024-09-28 05:56:04 +00:00
Create watchtower.sh
This commit is contained in:
parent
9231856294
commit
05a02e8187
61
watchtower.sh
Normal file
61
watchtower.sh
Normal file
@ -0,0 +1,61 @@
|
||||
function cleanup() {
|
||||
rm results.txt
|
||||
rm temp.txt
|
||||
}
|
||||
|
||||
function pull() {
|
||||
local base=$1
|
||||
local urls=("${!2}")
|
||||
|
||||
for resource in "${urls[@]}"
|
||||
do
|
||||
curl $base$resource --head \
|
||||
--location \
|
||||
--silent \
|
||||
--output /dev/null \
|
||||
--connect-timeout 2 \
|
||||
--write-out "%{url_effective} %{http_code}\n" &
|
||||
done
|
||||
|
||||
wait
|
||||
}
|
||||
|
||||
function parse() {
|
||||
local results=$1
|
||||
local remote=https://hooks.slack.com/services/foo/bar/baz # CHANGE THIS TO YOUR OWN SLACK HOOK
|
||||
|
||||
cat $results | awk '!/200/ { print $2 ": " $1 }' > temp.txt
|
||||
|
||||
while read line; do
|
||||
curl --header "Content-Type: application/json" \
|
||||
--silent \
|
||||
--output /dev/null \
|
||||
--request POST \
|
||||
--data "{\"text\": \"$line\"}" $remote &
|
||||
done < temp.txt
|
||||
|
||||
wait
|
||||
|
||||
display temp.txt
|
||||
}
|
||||
|
||||
function display() {
|
||||
printf "\n\n"
|
||||
cat $1
|
||||
printf "\n\n"
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
endpoints=(
|
||||
/newsbeat
|
||||
/newsbeat/popular
|
||||
/newsbeat/topics
|
||||
/newsbeat/topics/entertainment
|
||||
/newsbeat/topics/surgery
|
||||
/newsbeat/article/32792353/im-engaged-but-will-i-ever-be-able-to-marry-my-boyfriend
|
||||
)
|
||||
|
||||
pull http://bbc.co.uk endpoints[@] > results.txt
|
||||
display results.txt
|
||||
parse results.txt
|
Loading…
Reference in New Issue
Block a user