K
K
ksvdon2014-12-16 18:26:43
linux
ksvdon, 2014-12-16 18:26:43

Is it possible to use a variable from bash in expect?

I'll outline the gist.
On a remote machine, I need to get the user's UID. Then you need to perform actions on the same remote machine using this UID. Those. it must be obtained and somehow stored in a variable that would then be used.
query like this

send "cat /etc/passwd | grep myuser | awk -F ":" '{print $3}'\r"

did not pass because it is necessary to escape this "$3" apparently. And the backslash didn't fit
send "cat /etc/passwd | grep myuser >info.txt\r"
. On my machine I can get the UID but still a problem. It must also be inserted into the send "here =)" command, tell me how to insert a variable. (I will also be glad if you tell me with escaping so that the file is not copied in vain)
....
As I understand it, you need to somehow work with tcl variables? But I will get the number from bash...
********************
ANSWER: in bash we do export var=12345
then in the tcl environment itself (inside the expect entry):
send "$env(var)\r" (where env - Used for representing the array of elements that are environmental variables.)
tcl syntax
www.tutorialspoint.com/tcl-tk/tcl_special_variables.htm
********************

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor, 2014-12-16
@ksvdon

On a remote machine, I need to get the user's UID. Then you need to perform actions on the same remote machine using this UID. Those. it must be obtained and somehow stored in a variable that would then be used.

If I understand the essence of the question correctly, then you can write the result into a variable like this:
myvar=`cat /etc/passwd | grep myuser | awk -F ":" '{print $3}'\r`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question