Hi All,
I have some issues while retrieving variables specified in a script, using the Guest Script Manager Package.
Example of my script:
Bash:
myVar = "Hello World"
echo $myVar
When I execute the "Run in Script VM Guest", I noticed that the $myVar is empty/null
Any idea how can I retrieve this variable in the script?
Hi,
The first issue is that there should be no space characters around assignment operator, so the first line of your script should be
myVar="Hello World"
Then, I think there are several issues with the workflow 'Run Script In Guest' when preparing Bash command line. Could you open the workflow for edit, locate the scriptable task labeled 'set for Linux', and change its content to the following
scriptProgramPath = "/bin/bash";
script = script.replace(/\r\n/g, " ; ");
script = script.replace(/\n/g, " ; ");
script = script.replace(/\'/g, "\'\"\'\"\'");
scriptArguments = " > " + scriptOutputFile + " 2>&1 -c '" + script + "'";
useCmdAnsi = false;
Compare it with the original content below:
scriptProgramPath = "/bin/bash";
script = script.replace("\r\n", " ; ");
script = script.replace("\\\"", "'\"'");
script = script.replace(/\"/g, "\\\\\\\"");
scriptArguments = "-c \"bash > " + scriptOutputFile + " 2>&1 -c \\\"" + script + "\\\"\"";
useCmdAnsi = false;
So the differences are:
Note I'm not Bash guru so it's possible that the new version has its own issues, but for simple scripts like yours it should work.
Hi,
Thanks! It works fine now. However, I have issues getting it work in functions
function myFunction {
myVar="This is my variable"
echo $myVar
}
echo "Calling function"
myFunction
It is not returning any echo outputs. It seems like it is not executing the function.
Any ideas? Thanks!
Hi,
I have figured out that the echo in the function will not be outputting any values. However, I still have issues that the workflow executed successfully with no errors.
However, when I login to the VM itself, the required changes from the workflow were not updated. Has this got to do with the "Run Script In Guest" issues again?
Thanks
Yes, this is expected.
The code shown in the previous post that replaces "\r\n" and "\n" with ";" actually makes each line of the script to be treated as a separate shell command. If you want to execute a multi-line script you should comment these two lines in order for the whole script to be treated as a single Bash command.
I am having a problem getting the Guest Script Manager to execute a simple bash script:
cp /tmp/gg /tmp/gg2
Is there a reason why this bash command will not run? Is it the way that it's being interpreted when it is passed...I'm unsure. I am able to run this basic bash script:
sudo useradd [userName]
So I know that everything is working...just seems something is weird with syntax when it runs. Any ideas?