记OSV测试中写的两个Shell脚本

最近都很忙,一直在测试Novell公司的SLES操作系统的virtualization相关功能。其中stress部分要做Xen的hotplug SR-IOV VF 500遍以及当guest中assign一个VF时做24小时scp,写了两个简单Shell脚本,贴一下,留个纪念吧。
#!/bin/bash
#hot plug VF for 500 times
DomId=$(xl list | grep SLES | awk '{print $2}')
vf="01:10.0"
i=1
/root/pciback.sh -h $vf
echo "DomId=$DomId"
while [ $i -le 500 ]
do
    xl pci-attach $DomId $vf
    echo "${i}th time: hot pulg VF:$vf"
    if [ $i -ge 20 ]; then
        echo "please check VF in guest"
        sleep 30
    fi
    sleep 5
    xl pci-detach $DomId $vf
    echo "Detach VF:$vf"
    sleep 5
    i=$(($i+1))
done

另一个SCP 24小时:
#!/bin/bash
#scp for 24 hours
scp_log=/root/jay/scp-24h.log
begin_date=$(date +%s)
end_date=$(($begin_date+86400))
md5_host="$(md5sum file-4-scp)"
guest_ip="192.168.87.150"

function ping_guest()
{
    ping -c1 $guest_ip
    if [ $? -ne 0 ]; then
        echo "ping $guest_ip fails at $(date)" >> $scp_log
        return 1
    fi
    return 0
}

echo "--------scp-24.sh  begins at $(date) --------------" > $scp_log
present_date=$(date +%s)
counter=1
while [ $present_date -le $end_date ]
do
    ping_guest
    if [ $? = 1 ]; then
        sleep 10
        continue
    fi
    scp file-4-scp 192.168.87.150:/root/
    sleep 1
    md5_guest="$(ssh root@192.168.87.150 'md5sum file-4-scp')"
    if [ "xx$md5_host" = "xx$md5_guest" ]; then
        echo "${counter} time scp succeeds." >> $scp_log
    else
        echo "${counter} time scp fails at $(date)." >> $scp_log
        echo "md5_host=$md5_host"  >> $scp_log
        echo "md5_guest=$md5_guest" >> $scp_log
    fi
    counter=$(($counter+1))
    present_date=$(date +%s)
done
echo "--------scp-24.sh  ends at $(date) --------------" >> $scp_log

master

Stay hungry, stay foolish.

发表评论

邮箱地址不会被公开。 必填项已用*标注

*