yes, whenever you call
response = libs.run_bash(direct_source.connection, script_content, variables)
the script will get whatever the value of the "variables" array is at that point in time, the value will be dynamically resolved at invocation time, it will not be statically allocated.
for example:
variables = ["MY_VARIABLE": "my_value1"]
response1 = libs.run_bash(direct_source.connection, script_content, variables)
variables = ["MY_VARIABLE": "my_value2"]
response2 = libs.run_bash(direct_source.connection, script_content, variables)
------------------------------
Ankur Sarin
Senior Engineering Manager
Delphix
------------------------------
Original Message:
Sent: 07-31-2020 12:14:43 AM
From: Ravi Nistala
Subject: dynamically passing parameters to bash scripts
Thank you Ankur. The example you provided below makes sense. Hope you will update the online example to reflect the same.
So let us say my script (source_profile.sh) looks like as below and is stored in a folder called 'resources':
source $PATH_TO_PROFILE
can I use the following code, shown below, to pass the value to 'PATH_TO_PROFILE' dynamically
script_content = pkgutil.get_data('resources', 'source_profile.sh')
variables = {" PATH_TO_PROFILE ": "/home/username/.username.bash"}
# Execute script on remote host
response = libs.run_bash(direct_source.connection, script_content, variables)
I have additional question :
Can I change "/home/username/.username.bash" value based on a python variable dynamically?
Thanks & Regards
Ravi Nistala
+919949999282 (m)
Original Message:
Sent: 7/31/2020 12:51:00 AM
From: Ankur Sarin
Subject: RE: dynamically passing parameters to bash scripts
The example above represents a way to pass in variables, we will fix the command to show how to access the variables.
Here is another example, hope this helps:
Assume the "echoscript.sh" script is:
echo "$MY_VARIABLE" > /var/tmp/my_file
This can be called to create a file called "/var/tmp/my_file" with the content as "my_value" using the plugin code as following:
script_content = pkgutil.get_data('resources', 'echoscript.sh')variables = {"MY_VARIABLE": "my_value"}response = libs.run_bash(direct_source.connection, script_content, variables)
------------------------------
Ankur Sarin
Senior Engineering Manager
Delphix
Original Message:
Sent: 07-30-2020 11:14:53 PM
From: Ravi Nistala
Subject: dynamically passing parameters to bash scripts
Thank you Ankur for your response. I am not able to understand the example provided at https://developer.delphix.com/References/Platform_Libraries/#examples.
They are misleading. If you see the example below.
from dlpx.virtualization import libs
command = "echo 'Hi' >> /tmp/debug.log"
variables = {"var": "val"}
response = libs.run_bash(connection, command, variables)
print response.exit_code
print response.stdout
print response.stderr
The command contains no "var" as a parameter in the command. To me there is no point in passing 'variables" in this example.
Can you tell me how to use environment variables to pass values to a shell script in a directory? I can call the shell script without any variables which is inside a directory.
Thanks & Regards
Ravi Nistala
+919949999282 (m)
Original Message:
Sent: 7/30/2020 4:08:00 PM
From: Ankur Sarin
Subject: RE: dynamically passing parameters to bash scripts
Hey Ravi,
Unfortunately you cannot pass in variables via stdin. The only way to pass in variables to scripts is by using environment variables. Here is an example:
https://developer.delphix.com/References/Platform_Libraries/#examples
Would it be possible for you to modify the shell script to use environment variables instead?
The Virtualization SDK is also open source on GitHub: https://github.com/delphix/virtualization-sdk/. If you find any bugs, or have feature requests, please feel free to open a new issue and the engineering team will get back to you.
-Ankur
------------------------------
Ankur Sarin
Senior Engineering Manager
Delphix
Original Message:
Sent: 07-30-2020 02:11:12 PM
From: Ravi Nistala
Subject: dynamically passing parameters to bash scripts
I want to know how to pass parameters to a shell script file.
for ex:
My shell script(echoscript.sh) contains
echo $1
and i want to pass $1 dynamically to the following code how do i do it.
script_content = pkgutil.get_data('resources', 'echoscript.sh') # Execute script on remote host response = libs.run_bash(direct_source.connection, script_content)
------------------------------
Ravi Nistala
Community Member
TDGlobal
------------------------------