10秒钟后自动关机

#!/bin/bash
seconds_left=10
echo "请等待倒计时结束后自动关机..."
while [ $seconds_left -gt 0 ]
do
       echo -n $seconds_left
       sleep 1
       seconds_left=$(($seconds_left - 1))
       echo -ne "\r   \r"
done
shutdown -h now 
#!/bin/bash
read -p "您确定要关机吗?输入yes关机或者其他取消:" down_linux
seconds_left=10
case $down_linux in
"yes")
        echo "系统将在 $seconds_left 秒后关机,请等待倒计时结束后自动关机..."
        while [ $seconds_left -gt 0 ]
        do
                echo -n $seconds_left
                sleep 1
                seconds_left=$(($seconds_left - 1))
                echo -ne "\r   \r"
                        if [ $seconds_left -eq 0 ];then
                                echo `init \0`
                        fi
        done;;
"*")
        echo "您已取消关机。";;
esac

 

posted @ 2021-02-20 12:49  星火撩原  阅读(80)  评论(0编辑  收藏  举报