Write an ini key with name of variable value - node.js

I am trying to create an ini-database for every user that typed /boot (something).
But the problem is that I cannot write to ini. I need to do that:
Write into an ini section "boots" a key with a name of value of variable bootuserid. This is what I tried:
boots.'${bootuserid}'
boots.$bootuserid
boots.${bootuserid}
boots.(bootuserid)
All the scripts failed. So how do I make an ini key name of a value of variable?

You can use bracket notation to access a variable name with another variable:
boots[bootuserid]
I.e.
a={b:1}
myvar="b"
a[myvar] //returns 1

Related

Issue setting up a save path with integer variables and strings in kdb+

I am basically trying to save to data/${EPOCH_TIME}:
begin_unix_time: "J"$first system "date +%s"
\t:1 save `data/"string"$"begin_unix_time"
I am expecting it to save to data/1578377178
You do not need to cast first system "date +%s" to a long in this case, since you want to attach one string to another. Instead you can use
begin_unix_time:first system "date +%s"
to store the string of numbers:
q)begin_unix_time
"1578377547"
q)`$"data/",begin_unix_time
`data/1578377547
Here you use the comma , to join one string to another, then using cast `$ to convert the string to a symbol.
The keyword save is saving global data to a file. Given your filepath, it looks like youre trying to save down a global variable named 1578377547, and kdb can not handle variable names being purely numbers.
You might want to try saving a variable named a1578377547 instead, for example. This would change the above line to
q)`$"data/a",begin_unix_time
`data/a1578377547
and your save would work correctly, given that the global variable a1578377547 exists. Because you are sourcing the date down to the second from linux directly in the line you are saving a variable down to, this will likely not work, due to time constantly changing!
Also note that the timer system command will repeat it the execution n times (as in \t:n), meaning that the same variable will save down mutliple times given the second does not change. The time will also likely change for large n and you wont have anything assigned to the global variable you are trying to save should the second change.

Is there a way to input variable values from outside to terraform main file?

Is there a way I can input variable values from outside to terraform main file. It can be a excel sheet or sql db. Is it possible to do so ?
What you can't currently do is point you cmdline at a db i.e. to replace a tfvars file, but what you can set up in Terraform is to use a number of different key value stores:
consul
https://www.terraform.io/intro/examples/consul.html
aws parameter store (using a resource or data)
https://www.terraform.io/docs/providers/aws/d/ssm_parameter.html
There are quite a number of other key/value stores to choose from but there's no zero code solution and you will end up with lots of these statements:
Setup a key in Consul to provide inputs
data "consul_keys" "input" {
key {
name = "size"
path = "tf_test/size"
default = "m1.small"
}
}
There are many ways to do that;
You can use a tfvars file with all your inputs and you can use one file customer, user, environment
You can pass the variables to terraform executable on the command line
You can define environment files prefixed wit TF_VAR_[variable]
You can use https://www.terraform.io/docs/providers/aws/d/ssm_parameter.html as suggested above
You can even store variables in DynamoDB or any other database
You can use Consult+Vault as well

How I can create environment parameter in bash or from script

I want to create env parameter
that the key is a:b or a#b
I need to do it from bash script or from terminal , it should work from linux or windows
when I tried it export a:b=c
I got an error
not a valid identifier
When I tried
export tempKey = a:b then It worked but then I didn't know how to use the value a:b to create it as key
Could you please advise ?
None of the commonly used unix shells will let you create a var whose name includes characters not legal in an identifier (typically letters, digits and underscore). The simplest workaround is to use the env command since it doesn't impose any restrictions on the strings it puts in the environment. For example, env a:b=c a_cmd where a_cmd is whatever command needs that environment string. If you want it to be part of the shell's environment do exec env a:b=c $SHELL. Obviously the new shell won't be able to use that var since $a:b is not a valid var reference even if you enclose the var name in braces.

How do I append a string to a bash variable to return the value of another variable?

I am trying to get someone else's bash that sets various variables depending upon where a system comes up (z/VM Disaster Recovery provision). It is written so that it dots in a file containing variables with assigned values like this:
. /tmp/listofvars
IP=${SITE}IP
The value of the variable "$SITE" is set higher in the script, the result should be one of two things, either the value of the variable "$PRIP" for the production IP subnet value held in the variable list or the value of the variable "$DRIP" for the disaster recovery subnet value also held in the variable list that gets dotted in.
What actually happens is that the value of the $SITE variable gets concatenated to the string "IP" so the result is either "PRIP or "DRIP" depending on where I run the script. What I want is for the value of the $PRIP or $DRIP rather than the value of $SITE with the string 'IP' concatenated to it.
You can use variable reference as:
echo "${!IP}"
# will print value of $PRIP if $IP=PRIP

Copy value of 1 variable into another variable in UNIX

New to Unix not aware of the syntax structure so please excuse my syntax brevity.I am trying to copy a value of a variable and store that in another variable eg:
Two variables:
abc
bcd
Given:
abc=123
I want to copy the contents of abc i.e 123 in bcd. How to achieve this in Unix?
Earlier I was trying to copy the contents of abc in a .txt file which was working for me: see the code snippet below:
abc='123'
echo $abc >>/data/test/tt.txt
But know I want to copy them in another variable so I tried to do the following but was of no success.
abc='123'
test=`echo $abc>>bcd`
echo $test
Can you assist me in this?
Easy:
bcd="$abc"
For example:
abc="hello world"
The quotes there are necessary or else it will try to run a command named world with abc in its environment.
Actually, the quotes are not necessary (thanks to 1_CR for pointing this), but I like to add them for readability:
bcd=$abc
bcd="$abc"
They both do the same, exactly what you need.
Lastly, do not use single quotes, or else you will not get the value of the variable:
bcd='$abc'
Error! Now your bcd variable contains the literal value $abc.

Resources