View previous topic :: View next topic |
Author |
Message |
DaggyStyle Watchman
Joined: 22 Mar 2006 Posts: 5935
|
Posted: Sat Jan 04, 2025 1:35 pm Post subject: emulating controlling tty [solved] |
|
|
Greetings,
I need to send a cmd into virsh console and process it's output, tried various ways but I get this error:
Code: | error: Cannot run interactive console without a controlling TTY |
any idea how I can emulate controlling tty to achieve the above? _________________ Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein
Last edited by DaggyStyle on Sat Jan 04, 2025 2:54 pm; edited 1 time in total |
|
Back to top |
|
|
pingtoo Veteran
Joined: 10 Sep 2021 Posts: 1363 Location: Richmond Hill, Canada
|
Posted: Sat Jan 04, 2025 1:52 pm Post subject: |
|
|
Sound like you can use expect to start virsh and from there you can send (program) expect to issue command to virsh. But not knowing what do you mean by "send a cmd to virsh" I am just guessing. |
|
Back to top |
|
|
DaggyStyle Watchman
Joined: 22 Mar 2006 Posts: 5935
|
Posted: Sat Jan 04, 2025 1:58 pm Post subject: |
|
|
pingtoo wrote: | Sound like you can use expect to start virsh and from there you can send (program) expect to issue command to virsh. But not knowing what do you mean by "send a cmd to virsh" I am just guessing. |
tried to play around with expact, didn't got far, I assumed I didn't did it correctly.
for example send uname -m into the vm
e.g.
Code: |
$ expect -c "/bin/echo \"/bin/uname -m\" | virsh console vm"
invalid command name "/bin/echo"
while executing
"/bin/echo "/bin/uname -m" | virsh console vm"
|
_________________ Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein |
|
Back to top |
|
|
pingtoo Veteran
Joined: 10 Sep 2021 Posts: 1363 Location: Richmond Hill, Canada
|
Posted: Sat Jan 04, 2025 2:14 pm Post subject: |
|
|
you will need to let expect launch virsh. pipe will not work.
expect is based on TCL language. so it is a programming effort to do what you want.
A sample conceptual expect script do what you asking Code: | #!/usr/bin/expect -f
spawn "virsh console vm"
expect <<VM shell prompt string>>
send "/bin/uname -m\r" |
|
|
Back to top |
|
|
DaggyStyle Watchman
Joined: 22 Mar 2006 Posts: 5935
|
Posted: Sat Jan 04, 2025 2:44 pm Post subject: |
|
|
didn't seem to work, see this test:
Code: | $ expect << EOD
spawn "$(which virsh) console vm"
EOD
spawn /usr/bin/virsh console vm
couldn't execute "/usr/bin/virsh console vm": no such file or directory
while executing
"spawn "/usr/bin/virsh console vm"" |
_________________ Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein |
|
Back to top |
|
|
pingtoo Veteran
Joined: 10 Sep 2021 Posts: 1363 Location: Richmond Hill, Canada
|
Posted: Sat Jan 04, 2025 2:50 pm Post subject: |
|
|
DaggyStyle wrote: | didn't seem to work, see this test:
Code: | $ expect << EOD
spawn "$(which virsh) console vm"
EOD
spawn /usr/bin/virsh console vm
couldn't execute "/usr/bin/virsh console vm": no such file or directory
while executing
"spawn "/usr/bin/virsh console vm"" |
| Haven't been programming for long time. so I may got the syntax wrong.
it could be spawn /usr/bin/virsh console vm. i.e. no quoting. |
|
Back to top |
|
|
DaggyStyle Watchman
Joined: 22 Mar 2006 Posts: 5935
|
Posted: Sat Jan 04, 2025 2:54 pm Post subject: |
|
|
pingtoo wrote: | DaggyStyle wrote: | didn't seem to work, see this test:
Code: | $ expect << EOD
spawn "$(which virsh) console vm"
EOD
spawn /usr/bin/virsh console vm
couldn't execute "/usr/bin/virsh console vm": no such file or directory
while executing
"spawn "/usr/bin/virsh console vm"" |
| Haven't been programming for long time. so I may got the syntax wrong.
it could be spawn /usr/bin/virsh console vm. i.e. no quoting. |
removing the quoting worked, thanks for all the help _________________ Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein |
|
Back to top |
|
|
|