meta data for this page
  •  

ovm_functions.sh szkript

ovm_functions.sh
red=$'\e[1;31m'
grn=$'\e[1;32m'
yel=$'\e[1;33m'
blu=$'\e[1;34m'
mag=$'\e[1;35m'
cyn=$'\e[1;36m'
whi=$'\e[1;37m'
inv=$'\e[7;37m'
gry=$'\e[1;90m'
end=$'\e[0m'
 
function ovm_cli() {
        OVMCLI="ssh -n -o ServerAliveInterval=40 admin@localhost -p 10000"
        $OVMCLI $@
}
 
function kulcs_ellenorzes() {
if [[ $(ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=5 admin@localhost -p 10000 list manager |grep -c Success) -eq 0 ]]; then
        echo "Nincs SSH kulcs a CLI-hez, legeneralom:"
#       read -s -p "Add meg az oracle VM Manager administrator jelszavat: " OVM_PASSWD
        echo "Kulcs legeneralasa:"
        ssh-keygen -t rsa
        echo "Publikus kulcs masolasa a /home/oracle/.ssh/ovmcli_authorized_keys-be..."
        su - oracle -c "touch /home/oracle/.ssh/ovmcli_authorized_keys"
        cat ~/.ssh/id_rsa.pub >> /home/oracle/.ssh/ovmcli_authorized_keys
        echo "Elso kapcsolodas (jelszot ker):"
        ssh admin@localhost -p 10000 exit
        echo "Teszt kapcsolodas:"
        if [[ $(ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=5 admin@localhost -p 10000 list manager |grep -c Success) -eq 0 ]]; then
                echo "Sikertelen. Eddig tartott a tudomanyom, ellenorizd mi lehet a gond!"
                exit 1
        else
                echo "Sikeres!"
        fi
fi
}
 
function ovm_exec() {
# A fuggveny elso parametere az OVM CLI parancs, a masodik pedig, hogy milyen parametert adjon vissza a futas kimenetebol (Default: Id)
    OUTPUT=$(ovm_cli $1)
    RC=$?
    RET=${2:-[iI]d}
    ID=$(echo $OUTPUT | grep -oP "(?<=$RET:)[^ ]+(?= )")
    [[ -z $ID ]] && ID=$(echo $OUTPUT | grep -oP "(?<=$RET: )[^ ]+(?= )")
    [[ -z $ID ]] && ID=$(echo $OUTPUT | grep -oP "(?<=$RET = )[^ ]+(?= )")
    echo $ID
    return $RC
}
 
IPprefix_by_netmask() {
#function returns prefix for given netmask in arg1
 ipcalc -p 1.1.1.1 $1 | sed -n 's/^PREFIX=\(.*\)/\/\1/p'
}
 
function countdown()
{
    local delay=1
    local spinstr='9876543210'
    for I in 1 2 3 4 5 6  7 8 9 10; do
        local temp=${spinstr#?}
        printf " [%c]" "$spinstr"
        local spinstr=$temp${spinstr%"$temp"}
        sleep $delay
        printf "\b\b\b\b"
    done
    printf "    \b\b"
}