Parse data from a shell variable and resuse variable with new data - linux

I have a shell script that I use to do a few things requiring an actual IP address and the DNS name (for readability to the user).
A user will create a shell properties file containing variables that will be used in the script, and one of those variables contains a path and a DNS name for a server. It's setup like this:
PROJ="Blah"
SERVER_NAME="MyServer"
SERVER_PATH="/<path>/$SERVERNAME/aFile/"
In my script, I require the IP address of $SERVER_NAME. So I have a function that extracts the IP address, but I need to substitute that information into the $SERVER_PATH variable and then use the $SERVER_PATH variable. Is there anyway I can do this?

My answer was right in front of me the entire time. I just needed to replace $SERVER_NAME with the IP I obtained from my function.
I essentially just did SERVER_NAME=$SERVER_IP and that was it. I made it much more complicated than it needed to be!

Related

Configure optional DHCP usage in Terraform for vSphere

Using Terraform to configure vSphere vms, I'd like to be able to provide an IP address (and gateway and netmask) in the tfvars file, but have the vm default to using DHCP if the values are not provided. I know it will use DHCP if the 'vsphere_virtual_machine' resources' 'customize' block contains an empty 'network_interface' block. I was hoping that be giving a default value of "" to the settings in the variables.tf file I could set values if present and use DHCP if not, but I get an error stating:
Error: module.vm.vsphere_virtual_machine.node:
clone.0.customize.0.network_interface.0.ipv4_netmask: cannot parse ''
as int: strconv.ParseInt: parsing "": invalid syntax
So putting in a blank string won't parse, and it won't just leave the whole network_interface blank if the values are blank.
I can't use COUNT on a subresource, so the only thing I've come up with so far is to put two entire, nearly identical, 'vsphere_virtual_machine' resources into my module and then put COUNT statements on both so only one gets created, depending on whether the network settings are provided or not, but man, does that seem ugly...?
I think you are in luck. I've been waiting for this exact same problem to be solved since almost a year now.
Lo and behold, Terraform v0.12.0-alpha1:
They now support dynamic block definitions instead of just static ones
Enjoy, while I'm gonna throw away a couple of hundreds of lines worth of hacks just like the one you mentioned...

file transfer Extra attachmate appends username to host file name

Hi when I try to download a file from mainframe, using attachmate extra it appends the username also along with it. I dont know where to turn it off.
like for example - file name is yyyy.file.name, then when i try to transfer of file it transfers username.yyyy.file.name.
in 3.4 the option to append user name is turned off. Still its happening
Enclose the entire dataset name (including the high-level qualifier) in single quotes. This is a TSO (not JCL) convention - if you refer to a dataset without single quotes, it pre-pends your user ID as the high-level qualifier; however if you place single quotes around the dataset name it will take it 'as is' (well, it will uppercase it, since all z/OS dataset names are uppercase, but otherwise it will be 'as is').

Puppet create variable names using hiera

I want Puppet to create a different variable name depending on the hiera file associated with the environment. I want to do this because I want Puppet to use the ip address associated with a specific network interface. Ideally, the network interface will be in the hiera file. That way you could concatenate the ip_address variable name with the network interface defined in the hiera file, which would look something like.
::ipaddress_{$network_interface_from_hiera_file}
Is this possible?
Right now I have an the following, but I think there is a better implementation. If the network interfaces change I would have to add another case.
if $environment == 'production' {
$client_address = $::ipaddress_enp130s0f0
} else {
$client_address = $::ipaddress_eth2
}
It sounds like you're after an eval in Puppet, like you have in shell and Perl other languages, and as far as I know, there isn't one.
I would probably just use a custom fact that always returns the IP address I care about. Of course, then you need to solve the problem of how to get the custom facts out to your fleet.
Another solution might be to use Hiera's hierarchical lookup:
In hiera.yaml:
:hierarchy:
- %{::node_environment}
- common
In common.yaml:
---
myclass::client_address: "%{::ipaddress_eth2}"
In production.yaml:
---
myclass::client_address: "%{::ipaddress_enp130s0f0}"
Finally, be aware that you can look up values from within Hiera, see here. Possibly that could be helpful.

Two values for same field with Jinja2 in Ansible

I'm trying to set up a template in ansible, for our tomcat servers, but we have two tomcat instances on each host, each of which needs a different value for certain variables, for instance:
Tomcat_1 needs a port set to 8105
Tomcat_2 needs a port set to 8205
Easy enough to do if it's only one value per node needed, but I'm having some trouble finding how to do this when you need multiple values per host in either the Ansible or jinja2 docs. Can anyone offer some assistance, or point me to an example?
What I'm thinking is something along the lines of if this filepath then this value, but I'm not sure how to make that happen with jinja2.
I would either use two roles or use the role syntax that allows you to pass in values...
- { role: tomecat, some_parameter: 3 }

How to get command value from file or variable in Linux

I need to take the command value from file and execute the command,
in my scenario I am rinning this commands ON Terminal
uci set wireless.#wifi-iface[0].encryption=psk
uci set wireless.#wifi-iface[0].key="your_password"
uci commit wireless
wifi
but i need to pass the value of key i.e "your_password" dynamically i.e from file or from variable where I can store the value taken from python code.
so please tell me how can I pass this value dynamically and execute this commands successfully.
Thanks in Advance!!
Just use shell variable expansion, like this:
password='MYPASSWORD'
uci set wireless.#wifi-iface[0].key="$password"
The important thing here is the dollar sign in $password: which signals the shell that what you want is not the string password itself, but the value the variable password (defined before) points to.
If you want to read password's value from a file instead of defining it in inline, two approaches are available.
First approach
Create a configuration file (e.g. myscript.conf) and source it. E.g., myscript.conf will contain
password='MYPASSWORD`
and myscript will contain
source myscript.conf
uci set wireless.#wifi-iface[0].encryption=psk
uci set wireless.#wifi-iface[0].key="$password"
uci commit wireless
wifi
Be aware that this approach might have security flaws (everything you write into myscript.conf gets actually executed in the shell).
Second approach
Create a password file and just read its content. E.g., the password file will look like this
MYPASSWORD
I.e., it will contain just the password. On the other hand, myscript will be
password=$(cat password_file)
uci set wireless.#wifi-iface[0].encryption=psk
uci set wireless.#wifi-iface[0].key="$password"
uci commit wireless
wifi
Here we read the content of password_file by using cat and storing it into the variable password.

Resources