Latest LQ Deal: Linux Power User Bundle
Go Back > Blogs > zhjim
User Name


Rate this Entry

so cool socat

Posted 07-26-2013 at 03:26 AM by zhjim

Fiddeling around with kvm again I wanted to use the monitor but on an instance that run with "-display non" cause I run it from the command line. Maybe one can access the monitor from VNC or SPICE I don't know but I found the option to redirect the monitor to a socket or any other network device. I went for a socket like this
-qmp unix:/var/run/kvm/qmp-default.sock,server,nowait --monitor stdio
Possible options for -qmp are the same as for -serial and can be found in the man page. Some hints about qmp from here as a starter.

As the page I was following used netcat but mine did not had the -U option compiled in I installed socat which is another great tool and now is more of a friend to me then nc ever was. Sorry kitty its like so also it is not ne(a)t.

Now trying to shut down a machine through the monitor I had to first tell the monitor I want to go into cababilitie mode and then execute the system_powerdown command. Trying to just echo both of the commands then pipe did not work as one can tell. Failed json syntax and we need to wait for the answer from the socket after our first echo. What do to. RTFM I'd say and jup there goes the EXEC: option of socat. Its an ADDRESS TYPE which takes on a program which is started as an subprocess. That program now gets the input from socat and socat takes it output. Now I only had to use a little bit of bash with two echos a little sleep in between and my machines can go to bed too.

Heres the script as well as the call for socat
echo '{ "execute": "qmp_capabilities" }'
sleep 1
echo '{ "execute": "system_powerdown" }'
root@box:~/kvm# socat EXEC:./bin/ /var/run/kvm/qmp-default.sock
2013/07/26 10:20:47 socat[3832] E write(3, 0xd1df80, 16): Broken pipe
Just quick and dirty also I don't like the Broken pipe but thats just the qemu-monitor going away. One could just quit socat after sending last line to have that go away. Or pipe to /dev/null or just don't give a Oh hey kitty.
Posted in Uncategorized
Views 2476 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 04:46 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration