为了验证操作系统启动的稳定性,需要进行500次启动测试,便写了脚本实现。
脚本如下:
HOME=`pwd`
sleep 15
desktop_x86_4x(){
if [ ! -f /etc/reboot.sh ];then
cp -rf $HOME/reboot.sh /etc/
fi
if grep "reboot.sh" /etc/profile > /dev/null;
then
break;
else
echo "/bin/sh /etc/reboot.sh &" >> /etc/profile
fi
if id rebootuser > /dev/null 2>&1; then
break
else
useradd rebootuser
passwd rebootuser << TEST
abc123
abc123
TEST
echo "[Autologin]" >> /etc/sddm.conf
echo "Session=plasma.desktop" >> /etc/sddm.conf
echo "User=rebootuser" >> /etc/sddm.conf
fi
}
if id rebootuser > /dev/null 2>&1; then
break
else
desktop_x86_4x
fi
if [ ! -f /etc/tmpbash ];then
echo $1 >> /etc/tmpbash
fi
if [ ! -f /home/rebootuser/reboot.log ]; then
echo "Total=$1 , Times=0 , start at `date`" >> /home/rebootuser/reboot.log
chmod 777 /home/rebootuser/reboot.log
fi
times=`cat /etc/tmpbash`
n=`cat /home/rebootuser/reboot.log | awk -F, '{print $2}' | awk -F= '{print $2}' | tail -1`
if (( $n < $times ));then
N=$(($n + 1))
echo " Total=$times , Times=$N , reboot at `date`" >> /home/rebootuser/reboot.log
sleep 60
reboot
else
rm /etc/reboot.sh
sed -i '$d' /etc/profile
fi