]> Sergey Matveev's repositories - sgmon.git/commitdiff
Ability to have shebangless run-s
authorSergey Matveev <stargrave@stargrave.org>
Sun, 27 Mar 2022 09:48:47 +0000 (12:48 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 27 Mar 2022 09:48:47 +0000 (12:48 +0300)
README
probelist.sh
run.sh

diff --git a/README b/README
index 8454efe691d3b0f32fe5950f4d310f2c549679ee..87ad8dc91772a53c38a7c3783ceeaacf4b9ddf90 100644 (file)
--- a/README
+++ b/README
@@ -9,28 +9,21 @@ Create some directory hierarchy for convenience:
 
 Make probes from them:
 
-    $ cat > probes/example.com/ping4/run <<EOF
-    #!/bin/sh -e
-    "$SGMONDIR"/helper/http http://example.com/ Some.Expected.Title
-    EOF
+    $ echo '"$SGMONDIR"/helper/http http://example.com/ Some.Expected.Title'
+        > probes/example.com/ping4/run <<EOF
     # only 3 failures will generated notification email
     $ echo 3 > probes/example.com/http/max-attempts
 
-    $ cat > probes/example.com/ping4/run <<EOF
-    #!/bin/sh -e
-    "$SGMONDIR"/helper/ping 4 example.com
-    EOF
+    $ echo '"$SGMONDIR"/helper/ping 4 example.com' > probes/example.com/ping4/run
 
-    $ cat > probes/example.com/ping6/run <<EOF
-    #!/bin/sh -e
-    "$SGMONDIR"/helper/ping 6 example.com
-    EOF
+    $ echo '"$SGMONDIR"/helper/ping 6 example.com' > probes/example.com/ping6/run
     $ echo 5 > probes/example.com/ping4/period # every 5 seconds
 
     $ cat > probes/jails/foobar/run <<EOF
     #!/bin/sh -e
     jls -j foobar-jail-name
     EOF
+    $ chmod +x probes/jails/foobar/run
 
 Set default configuration values:
 
index 6cafcb2d3a837b600d07761cb342b2ce1a4f696f..28a4eb50826baca97ca5dfa3c7f6f74033259c3f 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh -e
 
 find . -mindepth 1 -type d -not -name ".*" | while read probe ; do
-    [ -x $probe/run ] || continue
+    [ -e $probe/run ] || continue
     echo ${probe#./}
 done | sort
diff --git a/run.sh b/run.sh
index 13ff28e8a32547c0165a149fc29532a18b11ce15..4bfc1a29c49cff600c28257ea79bbf7e9383ba5d 100755 (executable)
--- a/run.sh
+++ b/run.sh
@@ -12,7 +12,8 @@ ln -s $SGMONTMP state
 while : ; do
     [ -s max-attempts ] && read max_attempts < max-attempts || max_attempts=1
     [ -s state/attempts ] && read attempts < state/attempts || attempts=0
-    if ./run >state/stdout 2>state/stderr ; then
+    [ -x run ] && cmd=./run || cmd="sh -e run"
+    if $cmd >state/stdout 2>state/stderr ; then
         if [ "$attempts" -ge "$max_attempts" ] ; then
             "$SGMONDIR"/notify-ok.sh
         fi