-#!/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
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