0

if I run:

awk '/-jar org.eclipse.osgi.jar --launcher.suppressE/ {print "-Dcom.abc.service.gw.enableValidation=false \\"}1' rest_gw.sh >> new_gw.sh

the command inserts a new line above line -jar org.eclipse.osgi.jar --launcher.suppressE

-Djava.security.properties=/var/vcap/packages/helpers/data.properties \
-Dcom.abc.service.gw.enableValidation=false \  <<<<<<<<<<<<<<<<<<<<<<<<<
-jar org.eclipse.osgi.jar --launcher.suppressErrors -consoleLog &

If I run the following command, it gives: awk: line 1: runaway string constant "-Dcom.abc. ...

bosh -d test-105 ssh service/0 -c 'sudo /usr/bin/awk "/-jar org.eclipse.osgi.jar --launcher.suppressErrors/ {print \"-Dcom.abc.service.gw.enableValidation=false \\\"}1" /var/vcap/data/jobs/gw_rest/*/target/gw.sh >> /tmp/new_gw.sh'

Tried:

bosh -d test-105 ssh service/0 -c 'sudo /usr/bin/awk '\'/-jar org.eclipse.osgi.jar --launcher.suppressErrors/ {print \"-Dcom.abc.service.gw.enableValidation=false \\\"}1\' /var/vcap/data/jobs/gw_rest/*/target/gw.sh >> /tmp/new_gw.sh'

no luck so far. can someone suggest the correct way to do it? TYA!

EDIT:

sed command as recommended:

bosh -d test-105 ssh service/0 -c 'sudo sed '/-jar org.eclipse.osgi.jar --launcher.suppressE/i -Dcom.abc.service.gw.enableValidation=false \\' /var/vcap/data/jobs/gw_rest/*/target/gw.sh >> /tmp/new_gw.sh'

unknown flag launcher.suppressE/i'

This worked finally:

bosh -d test-105 ssh service/0 -c "sudo sed '/-jar org.eclipse.osgi.jar --launcher.suppressErrors -consoleLog/i -Dcom.abc.service.gw.enableValidation=false \\\' /var/vcap/data/jobs/gw_rest/*/target/gw.sh >> /tmp/new_gw.sh"
james
  • 132
  • 12
  • 1
    Try: `awk '/-jar org\.eclipse\.osgi\.jar --launcher.suppressErrors/ {print "-Dcom.abc.service.gw.enableValidation=false \\"}1'` – anubhava Oct 08 '20 at 09:24
  • Editing your scripts is probably not a good idea. Add a command-line parameter which adds this option if you pass in an option, and omits it otherwise. – tripleee Oct 08 '20 at 10:17

1 Answers1

0

I strongly suggest use sed command insert your line as:

sed  '/-jar org.eclipse.osgi.jar --launcher.suppressE/i -Dcom.abc.service.gw.enableValidation=false \\' rest_gw.sh >> new_gw.sh

It is cleaner and simple.

Dudi Boy
  • 4,551
  • 1
  • 15
  • 30
  • agree. we could do it with sed too. just that running the commands in a nested way is causing problems. – james Oct 08 '20 at 10:58
  • If i run the sed command as it is, it gives `unknown flag launcher.suppressE/i'`. Update the question. If i delete `launcher.suppressE`, it gives `unknown flag D'`. Have seen these problems with awk too. – james Oct 08 '20 at 11:07
  • You have quoting problem somewhere. I suggest you segment your scripts. to smaller chunks. run them manually in a sequence, put lots of `echo` messages, use the bash shell to conform with the standards. – Dudi Boy Oct 08 '20 at 11:18
  • You are right. it was indeed a quoting problem. i've updated the final outcome with `sed`. Thank you! :) – james Oct 08 '20 at 11:38