Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Patchviasocket via bash
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
while getopts "n:p:h" opt; do
case ${opt} in
n )
name=$OPTARG
;;
p )
cmdline=$(echo $OPTARG | tr '%' ' ')
;;
h ) echo "Usage: $0 -n [VM name] -p [command line]"
;;
esac
done
SOCK_FILE="/var/lib/libvirt/qemu/${name}.agent"
SSHKEY_FILE="/root/.ssh/id_rsa.pub.cloud"
if [ ! -e $SOCK_FILE ]; then
echo "Socket file $SOCK_FILE not found!"
exit 1
fi
if [ ! -e $SSHKEY_FILE ]; then
echo "SSH public key file $SSHKEY_FILE not found!"
exit 1
fi
MESSAGE="pubkey:$(cat $SSHKEY_FILE)\ncmdline:${cmdline}\n"
echo -e $MESSAGE | socat - UNIX-CONNECT:$SOCK_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.