socat ioctl error while using "qm terminal ..."

proxdrop

New Member
Aug 16, 2024
15
3
3
I have a setup where qm terminal works just fine from the command line. I'd like to programmatically pass and retrieve data to this serial device. I thought a construct similar to this would work, but I get ioctl errors on it.

Code:
qm terminal <vmid> <<EOF
    show version
EOF

Error is:

DATE TIME socat[1391302] E tcgetattr(0, 0x63c03419c3c0): Inappropriate ioctl for device

Presumably socat is used here and it doesn't like how I'm passing commands. Manually entering "qm terminal <vmid>" works fine, as does the "show version" command. Is there a "known" way to do this, or otherwise pass and retrieve data to a VM's serial port?
 
Hi,
you could try to connect to the socket yourself if you need a different configuration than the interactive terminal uses with socat. The socket path is /var/run/qemu-server/<ID>.serial<N>
 
  • Like
Reactions: proxdrop
Thanks. Ultimately I moved on to other options instead. I just don't know enough about socat and ptys in general, though maybe I'll eventually revisit.

I did get a "working" solution by launching qm terminal <vmid> inside of a screen session, then using screen -X stuff <data> to pass along my commands. Very janky, barely functional, but it did work.
 
Ah, it was a bit easier than I expected. I had to install netcat-openbsd for support for Unix sockets, but a simple nc -U /var/run/qemu-server/<vmid>.socket works mostly fine. There's some shenanigans with closing the connection after the script completes, but otherwise it seems workable.

EDIT: cat <testscript> | nc -U /var/lib/qemu-server/<vmid>.socket# -w 1 works perfectly fine. Next test would be assigning the results to a variable or file, but I won't bother to update the thread for that. Thanks for the help.
 
Last edited:
  • Like
Reactions: fiona

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!