Created
April 12, 2019 16:18
-
-
Save rohityadavcloud/aab23357fef2d8a530c0e83ec8be10c5 to your computer and use it in GitHub Desktop.
Patchviasocket via bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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