Remote Start VM via SSH

N20Visuals

Dabbler
Joined
Jan 16, 2021
Messages
21
Hi,

i‘m looking for a way to start a windows 10 vm via ssh or another way without logging in to the web UI.
I’m running openHAB and am planning to implement a switch to turn on said vm.

so far i‘ve tried to run the „virsh“ command but that doesn’t seem to work.
maybe someone can help me how I would do that the best way. Thanks!
 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,194
Have you checked the API docs? This is probably an option with the API.
 

tprelog

Patron
Joined
Mar 2, 2016
Messages
297
I have a script from another project, but you can probably use it to start your VM. Then, you could execute the script using an SSH command.

Just replace debian with the name of your Windows VM

Code:
#!/bin/bash

## Set the name of your VM
vm='debian'


if [ ${EUID} -ne 0 ]; then
  echo "Please run this script as root or using sudo" ; exit
fi

# get id and use it to start the VM
id=$(/usr/bin/midclt call vm.query | /usr/bin/jq -r '.[] | ( .id|tostring ) + ":" + .name' | /usr/bin/grep "${vm}" | /usr/bin/cut -f1 -d':')
/usr/bin/midclt call vm.start "${id}" &> /dev/null
 

N20Visuals

Dabbler
Joined
Jan 16, 2021
Messages
21
I have a script from another project, but you can probably use it to start your VM. Then, you could execute the script using an SSH command.

Just replace debian with the name of your Windows VM

Code:
#!/bin/bash

## Set the name of your VM
vm='debian'


if [ ${EUID} -ne 0 ]; then
  echo "Please run this script as root or using sudo" ; exit
fi

# get id and use it to start the VM
id=$(/usr/bin/midclt call vm.query | /usr/bin/jq -r '.[] | ( .id|tostring ) + ":" + .name' | /usr/bin/grep "${vm}" | /usr/bin/cut -f1 -d':')
/usr/bin/midclt call vm.start "${id}" &> /dev/null
Wow, this worked first try, thanks a lot!
 
Top