k332.feld.cvut.cz:STEP start/stop script invoked from mail
authorshort <>
Tue, 10 Jul 2001 18:34:30 +0000 (18:34 +0000)
committershort <>
Tue, 10 Jul 2001 18:34:30 +0000 (18:34 +0000)
bin/step.sh [new file with mode: 0755]

diff --git a/bin/step.sh b/bin/step.sh
new file mode 100755 (executable)
index 0000000..7aec497
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+NUM=0603431329
+MAILTO=+42$NUM@sms.paegas.cz
+SAFE="tr -cd 'a-zA-Z0-9\040.:\042\043\044\055/<>(){}'"
+t=/tmp/short.step.$$
+cd
+
+sendmail() {
+       (echo -n "\
+From: Step-activator <short+fromstep@ucw.cz>
+To: $MAILTO
+Content-Type: text/plain
+Content-Transfer-Encoding: 7bit
+
+$1"
+       if [ -f $t ];then
+         echo -n "&"
+         head -n $hd $t|grep "^From:"
+         fi
+       )|/usr/sbin/sendmail "$MAILTO"
+       rm -f $t*
+       exit;
+       }
+
+k332cmd () {
+       echo "$1;true"|ssh -o "BatchMode yes" k332.feld.cvut.cz sh &>$t.e || \
+         sendmail "ssh execute fail:`cat $t.e|$SAFE`"
+       }
+
+cat >$t
+hd="$[`sed -n -e '/^\$/=' -e '/^\$/q' <$t`+1]"
+id="`tail +$hd $t|head -n 1|$SAFE`"
+[ "$id" != 0 -a "$id" != 1 ] && \
+  sendmail "Command syntax:ID=$id"
+k332cmd "killall httpsd postmaster"
+if [ "$id" = 1 ];then k332cmd ". .profile &>/dev/null;./step/pgsql/bin/postmaster.run&./step/httpsd";fi
+sendmail "Ran, last res <`cat $t.e|$SAFE`>"