I have the following script that defines an OLD and a NEW string. I want to replace the OLD with the NEW using sed over a remote connection. All the commands besides the sed appear to be working. I have tried adjusting punctuation and using pipes instead of forward slashes with sed to no avail. Doing the sed command from a command prompt works, but within the script, it does not. I would appreciate any input on this.
#!/bin/ksh
OLD="command\[Check_Memory_OS_10038\]=/opt/tools/nagitem/libexec/check_mem.pl -w 80,10 -c 90,25";export OLD
NEW="command\[Check_Memory_OS_10038\]=/opt/tools/nagitem/libexec/check_mem_ng.sh -w 80 -c 90";export NEW
DEST1="/opt/tools/nagitem/libexec/"
DEST2="/opt/tools/nagitem/nrdp/clients/nrds/"
for x in `cat /home/joe/nagios/hostlist`
do
SSH_STATUS=$(ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no $USER@$x "pwd" >/dev/null)
if [[ $? = "0" ]];then
scp -p /home/joe/nagios/check_mem_ng.sh $x:/tmp
ssh -o "StrictHostKeyChecking no" $x "sudo /usr/localcw/bin/eksh -c '/bin/cp /tmp/check_mem_ng.sh $DEST1;chown nagitem:nagitem $DEST1/check_mem_ng.sh;cd $DEST2; /bin/sed -i -e 's/'$OLD'/'$NEW'/g' /opt/tools/nagitem/nrdp/clients/nrds/nrds.cfg '"
else
echo "Cannot connect to $x" >> badhosts
fi
done
Error received is: /bin/sed: -e expression #1, char 39: unknown option to `s'
/
, which is the default delimiter in thes///
command. Either escape them in your strings, or use another delimiter character (s@@@
?).ssh -o "StrictHostKeyChecking no" $x "sudo /usr/localcw/bin/eksh -c '/bin/cp /tmp/check_mem_ng.sh $DEST1;chown nagitem:nagitem $DEST1/check_mem_ng.sh;cd $DEST 2; /bin/sed -i -e 's|'$OLD'|'$NEW'|g' /opt/tools/nagitem/nrdp/clients/nrds/nrds.cfg '"