perl pbased version that works on IP04
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 30 Oct 2012 03:53:16 +0000 (03:53 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 30 Oct 2012 03:53:16 +0000 (03:53 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@895 01035d8c-6547-0410-b346-abe4f91aad63

mini-asterisk-gui2/cgi-bin/setlinekey2.cgi

index 85aa6ad8e59d32cb9320373c87155176c5f1f91c..55efdb0b1bc5a536a49e7477e10069d60763b268 100755 (executable)
@@ -1,13 +1,19 @@
-#!/bin/sh -x
+#!/bin/sh 
 # setlinekey2.cgi
 # David Rowe 29 Oct 2012
 #
-# CGI to set the text in "file" from "this" to "that"
+# CGI to set the text in "file" from "this" to "that" on lines with text "key"
 #
 # Test on host with:
 #
-#    $ export QUERY_STRING='file=test.txt&this=IPADDRESS=&that=192.168.1.31&key=mykey'; ./setlinekey.cgi
+#    $ export QUERY_STRING='file=test.txt&this=host=&that=192.168.1.31&key=Jazmin mini'; ./setlinekey2.cgi
 #
+# using test file:
+# 
+#   root:/root> cat test.txt 
+#   host=192.168.1.28       ; Jazmin mini-asterisk do not remove this comment
+#   dtmfmod=rfc2833         ; Jazmin mini-asterisk do not remove this comment
+#   host=192.168.1.29       ; SIP mini-asterisk do not remove this comment
 
 cat <<EOF
 Content-type: text/html
@@ -31,8 +37,10 @@ echo $that
 echo $key
 if [ -f $file ]; then
 #  sed -i  "s/\($this\)[a-z0-9\.]*\(.*$key.*\)/\1$that\2/"  $file
-rhs=`cat $file | grep -oe "$this.*$key" | grep -oe "$this[a-z0-9\.]*" | sed -n "s/$this//p"`
-cat $file | sed "s/$rhs/$that/"
+#rhs=`cat $file | grep -oe "$this.*$key" | grep -oe "$this[a-z0-9\.]*" | sed -n "s/$this//p"`
+#cat $file | sed "s/$rhs/$that/"
+# testversion:
+perl -i -pe "s/($this)[a-z0-9\.]*(.*$key.*)/$this$that\$2/" $file
 else
   echo "$file does not exist"
 fi