X7ROOT File Manager
Current Path:
/var/VMOptimizationToolsLinux
var
/
VMOptimizationToolsLinux
/
π
..
π
LinuxUpdate.XML
(645 B)
π
SangforVMSTool
(3.11 KB)
π
SangforVMSTool.service
(194 B)
π
action_common.sh
(13.34 KB)
π
busybox_cmd_ln.sh
(2.24 KB)
π
collect_test_data.sh
(1.16 KB)
π
common_config.sh
(278 B)
π
data_test_tool.sh
(12.59 KB)
π
debian_vmconfig.sh
(10.74 KB)
π
guest_system_config.sh
(1.82 KB)
π
log.sh
(1.36 KB)
π
mod_test.sh
(3.69 KB)
π
mod_test1.sh
(914 B)
π
net_common.sh
(915 B)
π
redhat_vmconfig.sh
(11.14 KB)
π
sangfor_guest_datareport
(21.66 KB)
π
sangfor_heartalive.sh
(2.37 KB)
π
sangfor_module_update
(28.11 KB)
π
sangfor_set_network.sh
(504 B)
π
sangfor_sfping
(3.85 KB)
π
sangfor_sshkey_gen
(1.29 KB)
π
sangfor_update_ipc_callback
(5.29 KB)
π
sangfor_vm_proxyd
(3.45 KB)
π
sangfor_vm_proxyd_r
(4.4 KB)
π
sangfor_vm_proxyd_w
(1.32 KB)
π
sangfor_vmconfig
(2.4 KB)
π
sangfor_vmconfig_common
(27.99 KB)
π
sangfor_vmconfig_ipc_callback
(4.75 KB)
π
sangfor_watchdog
(3.95 KB)
π
sfping.c
(15.68 KB)
π
sfping.pl
(6.15 KB)
π
startall
(1.78 KB)
π
stopall
(1.11 KB)
π
suse_vmconfig.sh
(6.19 KB)
π
tools_x64
π
tools_x86
π
uni_test.sh
(2.59 KB)
π
update_common_func
(4.35 KB)
π
update_common_header
(4.86 KB)
π
update_config
(2.89 KB)
π
update_install
(28.84 KB)
π
virtio_nic_attr_set.sh
(2.42 KB)
π
virtio_nic_compat.sh
(5.28 KB)
π
vm_ip_recover.sh
(16.66 KB)
π
vm_ipc.sh
(9.06 KB)
π
vmconfig_common_func
(10.76 KB)
π
vmconfig_common_header
(3.37 KB)
π
vmconfig_config
(805 B)
π
vmtools-install.sh
(31.16 KB)
π
watch_test.sh
(313 B)
π
watchdog.sh
(1.39 KB)
π
x64
π
x86
Editing: vmconfig_common_func
#!/bin/bash #The common file. declare g_debian_network_cfg="/etc/network/interfaces" declare g_debian_network_cfg_dir="/etc/network/interfaces.d" declare g_redhat_network_cfg_dir="/etc/sysconfig/network-scripts" declare g_network_manager_connection_dir="/etc/NetworkManager/system-connections" declare g_suse_network_cfg_dir="/etc/sysconfig/network" declare g_suse_routes_config_file="/etc/sysconfig/network/routes" declare g_dns_config_file="/etc/resolv.conf" declare g_dns_netconfig_file="/etc/resolv.conf.netconfig" declare g_suse_netconfig_file="/etc/sysconfig/network/config" declare g_networkmanager_config_file="/etc/NetworkManager/NetworkManager.conf" # get the CIDR prefix from a dot-decimal netmask # param $1: netmask. eg: 255.255.255.0 # output: CIDR prefix. eg: 24 # return: none mask2cdr () { # Assumes there's no "255." after a non-255 byte in the mask local x=${1##*255.} set -- 0^^^128^192^224^240^248^252^254^ $(( (${#1} - ${#x})*2 )) ${x%%.*} x=${1%%$3*} echo $(( $2 + (${#x}/4) )) } # get the dot-decimal netmask from a CIDR prefix # param $1: CIDR prefix. eg: 24 # output: netmask. eg: 255.255.255.0 # return: none cdr2mask () { # Number of args to shift, 255..255, first non-255 byte, zeroes set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0 [ $1 -gt 1 ] && shift $1 || shift echo ${1-0}.${2-0}.${3-0}.${4-0} } get_ifname_by_mac() { local macaddr=$1 ip link >/dev/null 2>&1 if [ $? -eq 0 ];then ip link |grep -i -B 1 ${macaddr} |awk '{if (NR==1)print $2}'|awk -F: '{print $1}' fi return 0 } # get ip address of interface # param $1: ifname, eg: eth0 # output: ip address eg:192.168.10.10 # return: none get_if_ip() { local ifname=$1 ip link >/dev/null 2>&1 if [ $? -eq 0 ];then ip addr show dev ${ifname} |awk '{if($1~/^inet$/)print $2}'|awk -F/ '{print $1}' else ifconfig >/dev/null 2>&1 if [ $? -eq 0 ];then ifconfig ${ifname} |awk '{if($1~/^inet$/)print $2}'|awk -F: '{print $2}' fi fi } # get netmask of interface # param $1: ifname, eg: eth0 # output: netmask eg:255.255.255.0 # return: none get_if_mask() { local ifname=$1 local int_netmask ip link >/dev/null 2>&1 if [ $? -eq 0 ];then int_netmask=`ip addr show dev ${ifname} |awk '{if($1~/^inet$/)print $2}'|awk -F/ '{print $2}'` cdr2mask ${int_netmask} else ifconfig >/dev/null 2>&1 if [ $? -eq 0 ];then ifconfig ${ifname} |awk '{if($1~/^inet$/)print $4}'|awk -F: '{print $2}' fi fi } # get default gateway of interface # param $1: ifname, eg: eth0 # output: gateway eg: 192.168.10.1 # return: none get_if_gateway() { local ifname=$1 local int_netmask ip route >/dev/null 2>&1 if [ $? -eq 0 ];then ip route | grep default | awk -v ifname="$ifname" '{if ($5==ifname) print $3}' fi } # get current conneted uuid of interface # param $1: ifname,eg:eth0 # return 0(success),1(fail) nmcli_get_connected_uuid() { local ifname=$1 local uuid="" test -z "$ifname" && return 1 nmcli c list >/dev/null 2>&1 if [ $? -eq 0 ];then uuid=`nmcli -f UUID,DEVICES c status |awk -v ifname="$ifname" '{if ($2==ifname) print $1}'` else uuid=`nmcli -f UUID,DEVICE c show --active|awk -v ifname="$ifname" '{if ($2==ifname) print $1}'` fi echo $uuid return 0 } # get current conneted config id of interface by nmcli # param $1: ifname,eg:eth0 # output: method(manual|auto|"") # return 0(success),1(fail) nmcli_get_config_ip_method() { local ifname=$1 local uuid="" local method="" test -z "$ifname" && return 1 uuid=`nmcli_get_connected_uuid "$ifname"` test -z "$uuid" && return 1 nmcli c list >/dev/null 2>&1 if [ $? -eq 0 ];then method=`nmcli c list uuid "$uuid" | grep "ipv4.method" |awk -F: '{print $2}'` else method=`nmcli c show uuid "$uuid" | grep "ipv4.method" |awk -F: '{print $2}'` fi echo $method return 0 } # get current config ip of interface by nmcli # param $1: ifname,eg:eth0 # output: ipaddr,eg. 192.168.100.10 # return 0(success),1(fail) nmcli_get_config_ip() { local ifname=$1 local uuid="" test -z "$ifname" && return 1 uuid=`nmcli_get_connected_uuid "$ifname"` test -z "$uuid" && return 1 nmcli c list >/dev/null 2>&1 if [ $? -eq 0 ];then addresses_value=`nmcli c list uuid "$uuid" | grep "ipv4.addresses" |awk -F: '{print $2}'` # { ip = 192.168.1.10/24, gw = 192.168.1.1 }; { ip = 192.168.2.10/24, gw = 192.168.2.1 } ip=`echo $addresses_value | awk -F "ip =" '{print $2}'|awk -F "/" '{print $1}'` else addresses_value=`nmcli c show uuid "$uuid" | grep "ipv4.addresses" |awk -F: '{print $2}'` # 192.168.50.12/24, 192.168.51.12/24 ip_cdr=`echo $addresses_value |awk -F "," '{print $1}'` ip=`echo "$ip_cdr" | awk -F "/" '{print $1}'` fi echo $ip return 0 } # get current config ip of interface by nmcli # param $1: ifname,eg:eth0 # output: netmask,eg. 255.255.255.0 # return 0(success),1(fail) nmcli_get_config_mask() { local ifname=$1 local uuid="" test -z "$ifname" && return 1 uuid=`nmcli_get_connected_uuid "$ifname"` test -z "$uuid" && return 1 nmcli c list >/dev/null 2>&1 if [ $? -eq 0 ];then addresses_value=`nmcli c list uuid "$uuid" | grep "ipv4.addresses" |awk -F: '{print $2}'` # { ip = 192.168.1.10/24, gw = 192.168.1.1 }; { ip = 192.168.2.10/24, gw = 192.168.2.1 } ip_cdr=`echo $addresses_value | awk -F "ip =" '{print $2}'|awk -F "," '{print $1}'` else addresses_value=`nmcli c show uuid "$uuid" | grep "ipv4.addresses" |awk -F: '{print $2}'` # 192.168.50.12/24, 192.168.51.12/24 ip_cdr=`echo $addresses_value |awk -F "," '{print $1}'` fi if ! test -z "$ip_cdr";then cdr=`echo "$ip_cdr" | awk -F "/" '{print $2}'` cdr2mask $cdr fi return 0 } # get current config gateway of interface by nmcli # param $1: ifname,eg:eth0 # output: gateway,eg. 192.168.100.1 # return 0(success),1(fail) nmcli_get_config_gateway() { local ifname=$1 local uuid="" test -z "$ifname" && return 1 uuid=`nmcli_get_connected_uuid "$ifname"` test -z "$uuid" && return 1 nmcli c list >/dev/null 2>&1 if [ $? -eq 0 ];then addresses_value=`nmcli c list uuid "$uuid" | grep "ipv4.addresses" |awk -F: '{print $2}'` # { ip = 192.168.1.10/24, gw = 192.168.1.1 }; { ip = 192.168.2.10/24, gw = 192.168.2.1 } gateway=`echo $addresses_value | awk -F "gw =" '{print $2}'|awk -F "}" '{print $1}'` else gateway=`nmcli c show uuid "$uuid" | grep "ipv4.gateway" |awk -F: '{print $2}'` fi echo $gateway return 0 } # check dns is already exist in config # param $1: dns # return 0(exist),1(not exist) check_dns_exist() { local dns=$1 for i in `cat /etc/resolv.conf | grep "^\s*nameserver"|awk '{print $2}'` do if [ x"$dns" == x"$i" ];then log_debug "found dns:$dns" return 0 fi done log_debug "not found dns:$dns" return 1 } # get current dns num # param: none # output: dns num # return: none get_sys_dns_num() { cat /etc/resolv.conf |grep "^\s*nameserver" | wc -l } # remove quotation mark of str # param$1: str # output: str after remove quotation mark # return: none remove_quotation_mark() { local str=$1 if ! test -z "$str";then str=`echo $str | sed $'s/\'//g'` str=`echo $str | sed $'s/"//g'` fi echo $str } # get value from config file # key value format: key=value # param $1: config file # param $2: key # output: value of key # return: none get_value_from_config() { local file=$1 local key=$2 value=`cat "$file" |grep "^\s*$key" |awk -F= '{if (NR==1) print $2}'` if ! test -z "$value";then value=`remove_quotation_mark "$value"` fi echo $value } is_network_manager_enable() { if [ ! -e "$g_networkmanager_config_file" ];then return 1 fi enable=`cat $g_networkmanager_config_file | grep "managed"|awk -F= '{print $2}'` if [ x"$enable" == x"true" ];then return 0 else return 1 fi } enable_network_manager() { if test -f "$g_networkmanager_config_file";then sed -i '/^\s*managed/s/false/true/' "$g_networkmanager_config_file" fi } disable_network_manager() { if test -f "$g_networkmanager_config_file";then sed -i '/^\s*managed/s/true/false/' "$g_networkmanager_config_file" fi } # check if interface config is changed # param $1: ifname,eg:eth0 # param $2: ip,eg:192.168.100.100 # param $3: net mask,eg:255.255.255.0 # param $4: gateway,eg:192.168.100.1 # param $5: primary dns,eg:192.168.100.1 # param $6: secondary dns,eg:8.8.8.8 # return 0(changed),1(not changed) check_if_config_changed() { local ifname=$1 local ipaddr=$2 local netmask=$3 local gateway=$4 local dns1=$5 local dns2=$6 local cur_ip=`get_if_ip $ifname` local cur_mask=`get_if_mask $ifname` local cur_gateway=`get_if_gateway $ifname` if ! test -z "$ipaddr";then if [ x"${cur_ip}" != x"${ipaddr}" ];then log_debug "ip changed $ifname $cur_ip,$ip" return 0 fi if [ x"${cur_mask}" != x"${netmask}" ];then log_debug "mask changed $ifname $cur_mask,$netmask" return 0 fi if [ x"${cur_gateway}" != x"${gateway}" ];then log_debug "gateway changed $ifname $cur_gateway,$gateway" return 0 fi fi if ! test -z "$dns1";then check_dns_exist "$dns1" if [ ! $? -eq 0 ]; then log_debug "dns1 changed $ifname $dns1" return 0 fi fi if ! test -z "$dns2";then check_dns_exist "$dns2" if [ ! $? -eq 0 ]; then log_debug "dns2 changed $ifname $dns2" return 0 fi fi log_debug "network status not change" return 1 } # param $1: inet address,eg: 192.168.10.10 # return 0(valid),1(not valid) is_valid_inet_address() { if [ $# -ne 1 ];then return 1 fi addr=$1 if [[ $addr =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then field1=$(echo $addr|cut -d. -f1) field2=$(echo $addr|cut -d. -f2) field3=$(echo $addr|cut -d. -f3) field4=$(echo $addr|cut -d. -f4) if [ $field1 -le 255 -a $field2 -le 255 -a $field3 -le 255 -a $field4 -le 255 ]; then return 0 else return 1 fi else return 1 fi } # brief ζ£ζ₯ζ―ε¦ζ―ζζηη½ε‘macε°ε,δΎε¦ FE:FC:FE:66:82:31 # return 0(valid),1(not valid) is_valid_mac_address() { if [ $# -ne 1 ];then return 1 fi macaddr=$1 if [[ $macaddr =~ ^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$ ]]; then return 0 fi return 1 }
Upload File
Create Folder