Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
emulating controlling tty [solved]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
DaggyStyle
Watchman
Watchman


Joined: 22 Mar 2006
Posts: 5935

PostPosted: Sat Jan 04, 2025 1:35 pm    Post subject: emulating controlling tty [solved] Reply with quote

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
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1363
Location: Richmond Hill, Canada

PostPosted: Sat Jan 04, 2025 1:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
DaggyStyle
Watchman
Watchman


Joined: 22 Mar 2006
Posts: 5935

PostPosted: Sat Jan 04, 2025 1:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1363
Location: Richmond Hill, Canada

PostPosted: Sat Jan 04, 2025 2:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
DaggyStyle
Watchman
Watchman


Joined: 22 Mar 2006
Posts: 5935

PostPosted: Sat Jan 04, 2025 2:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
pingtoo
Veteran
Veteran


Joined: 10 Sep 2021
Posts: 1363
Location: Richmond Hill, Canada

PostPosted: Sat Jan 04, 2025 2:50 pm    Post subject: Reply with quote

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
View user's profile Send private message
DaggyStyle
Watchman
Watchman


Joined: 22 Mar 2006
Posts: 5935

PostPosted: Sat Jan 04, 2025 2:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum