Split configuration
This commit is contained in:
parent
84b22a3cf3
commit
96884c256b
3 changed files with 25 additions and 11 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
_state
|
||||
config.sh
|
||||
|
|
10
config.sh.sample
Normal file
10
config.sh.sample
Normal file
|
@ -0,0 +1,10 @@
|
|||
STATE_DIR="$(dirname $(readlink -f "$0"))/_state"
|
||||
URLS=(
|
||||
'https://tmp.tobast.fr/testcurl'
|
||||
)
|
||||
PATTERNS=(
|
||||
'1'
|
||||
)
|
||||
MESSAGES=(
|
||||
'match'
|
||||
)
|
25
curlgrep.sh
25
curlgrep.sh
|
@ -1,16 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
STATE_DIR="$(dirname $(readlink -f "$0"))/_state"
|
||||
URLS=(
|
||||
'https://tmp.tobast.fr/testcurl'
|
||||
)
|
||||
PATTERNS=(
|
||||
'1'
|
||||
)
|
||||
MESSAGES=(
|
||||
'match'
|
||||
)
|
||||
source "$(dirname $(readlink -f "$0"))/config.sh"
|
||||
|
||||
function do_notify {
|
||||
msg="$1"
|
||||
curl "http://[::1]:51641/plain" -F message="$msg"
|
||||
}
|
||||
|
||||
function do_one {
|
||||
if [ "$#" -lt 4 ] ; then
|
||||
|
@ -24,17 +19,25 @@ function do_one {
|
|||
elt_id="$4"
|
||||
state_path="$STATE_DIR/$elt_id"
|
||||
|
||||
echo -n "Polling $url… "
|
||||
|
||||
curl -s "$url" | grep -q "$pattern"
|
||||
no_match="$?"
|
||||
|
||||
if [ "$no_match" -eq 1 ]; then
|
||||
if [ -f "$state_path" ] ; then
|
||||
echo "no match anymore"
|
||||
rm -f "$state_path"
|
||||
else
|
||||
echo "still no match"
|
||||
fi
|
||||
else # match
|
||||
if ! [ -f "$state_path" ] ; then # no previous match
|
||||
echo "NEW MATCH: $msg"
|
||||
echo "now matches"
|
||||
touch "$state_path"
|
||||
do_notify "$msg"
|
||||
else
|
||||
echo "still matches"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue