Question

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!!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top