I am trying to build a bash script dynamically and created the file on rackspace centos instance and one of the following behave differently not sure what i am missing here.
String script = new ScriptBuilder()
.addStatement(exec("echo ' expect \"Enter Password :\"' >> config.sh "))
.addStatement(exec("echo ' send -- \"123\"' >> config.sh "))
.addStatement(exec("echo ' send -- \"\\r\"' >> config.sh "))
.render(OsFamily.UNIX);
When I loggin to the box and view config.sh .
expect "Enter Password:"
send -- "123"
"send --"
But I want to see
expect "Enter Password:"
send -- "123"
send -- "\r"
I am not sure what I am doing wrong.
Instead of directly using the ScriptBuilder
class, it is a better idea to use the Statements
helper class. It has a couple methods that might help you:
Both scripts are a better option that directly using the ScriptBuilder
. If you end up with more than one statement, you can add them to a StatementList
(which is also a Statement).