我目前正在使用Solusvm和Windows 10 / server 2016工作我必须从以下位置更改XML:
<cpu match='exact' mode='host-model'>
<topology sockets='1' cores='2' threads='2'/>
</cpu>
为:
<cpu mode='custom' match='exact'>
<topology sockets='1' cores='2' threads='2'/>
<model fallback='allow'>kvm64</model>
<feature policy='require' name='nx'/>
<feature policy='require' name='lahf_lm'/>
</cpu>
我需要为存在该拓扑的所有VPS执行此操作。这是我目前的代码:
for d in */; do
FILES=/home/kvm/kvm101/kvm*.xml;
shopt -s nullglob;
for file in $FILES; do
echo $file;
# Check that exactly 3 values were passed in
echo "DEBUG: Starting... [Ok]\n"
echo "DEBUG: searching For CPU Block \n"
# Creating a temporary file for sed to write the changes to
xml=$file
echo $xml;
temp_file=$file".temp"
CPU="cpu match='exact' mode='host-model'"
CPUEND="cpu"
BLANK="test"
# Extracting the value from the <$CPU> element
el_value=`grep “<$CPU>.*<.$CPUEND>” $xml | sed -e “s/^.*<$CPU/<$CPUEND/” | cut -f2 -d”>”| cut -f1 -d”<”`
echo "DEBUG: Found the current value for the element <$CPU> - '$el_value'"
# Replacing elemen’s value with $3
sed -e “s/<$CPU>$el_value<\/$CPU>/<$CPU>$BLANK<\/$CPU>/g” $file > $temp_file
done; \
shopt -u nullglob;
done
错误日志:
[root@vpskvm1 kvm101]# /home/kvm/test2.sh
/home/kvm/kvm101/kvm101.xml
DEBUG: Starting... [Ok]
DEBUG: searching For CPU Block
/home/kvm/kvm101/kvm101.xml
/home/kvm/test2.sh: line 25: cpu match='exact' mode='host-model': No such file or directory
/home/kvm/test2.sh: line 25: cpu match='exact' mode='host-model'/: No such file or directory
DEBUG: Found the current value for the element <cpu match='exact' mode='host-model'> - ''
/home/kvm/test2.sh: line 30: cpu match='exact' mode='host-model': No such file or directory