linux - Bash Whiptail ping 进度条

标签 linux wget whiptail

我正在尝试使用 Whiptail 制作一个进度条,它可以正确跟踪 wget ping 的进度。

我的目标是创建一个脚本,通过对 google.com 执行 ping 命令来测试您的互联网,当发生这种情况时,它会使用 whiptail 向您显示进度,然后如果您可以上网,它会向您发送一个 msgbox,否则它将向您显示是或否的 whiptail,它会询问您是否要继续。

我目前的尝试:

    #!/bin/bash

    #Make ping and display proces

        #Progres bar GUI using whiptail(Native Gui)
        while true do
            # Check internet status, ping google.com
            wget -q --tries=20  --timeout=10 --spider http://google.com

        done| whiptail --title "Internet Validation" --gauge "${ping}" 6 60 0


    #If for validating Internet conexion
    if [ $? -eq 0 ]; then
        #If succes int variable change to Online 
        int="Online"
        #And Whiptail GUI disaply confimacion box
        whiptail --title "Succes" --msgbox "Internet Status: $int. Choose Ok to continue." 10 60

    #Internet validation opcion for when there is not internet
    else
        #Int Variable change to Offlien
        int="Offline"
        #Whiptail display Internet Status: Offline and ask if it whants to continue
        if (whiptail --title "Conexion Error" --yesno "Internet Status: $int, Continue?" 10 60) then
            #Function to install Nos Software
            $(function)
        else
            #Whiptail display installetion cancel
            whiptail --title "Installation" --msgbox "The Installation has been cancel." 10 60
        fi
    fi

    #Save in logfile Status of internet
    echo "`date -u` 'Internet Status: $int'" >> logfile.txt

最佳答案

我找到了一个可行的方法
更新的解决方案

#!/bin/bash

#Progres bar GUI using whiptail(Native Gui)
{
    #Start progress bar in 0
    i="0"
    # Maximum number to try.
    ((count = 100))

    #Make ping and display proces
    while [[ $count -ne 0 ]] ; do

        # Check internet status, ping google.com; ping once
        ping -c 1 google.com
        rc=$?

        # If okay, flag to exit loop.
        if [[ $rc -eq 0 ]] ; then
            ((count = 1))
        fi
        # So we don't go forever.
        ((count = count - 1))

        #For progress bar
        sleep 1
        echo $i
        i=$(expr $i + 1)
    done
    # If it is done then display 100%
    echo 100
    # Give it some time to display the progress to the user.
    sleep 2
#Display Ping progress bar
} | whiptail --title "Internet Validation" --gauge "validating Conexion" 6 60 0

#If for validating Internet conexion
if [ $? -eq 0 ]; then
    #If succes int variable change to Online 
    int="Online"
    #And Whiptail GUI disaply confimacion box
    whiptail --title "Succes" --msgbox "Internet Status: $int. Choose Ok to continue." 10 60

#Internet validation opcion for when there is not internet
else
    #Int Variable change to Offlien
    int="Offline"
    #Whiptail display Internet Status: Offline and ask if it whants to continue
    if (whiptail --title "Conexion Error" --yesno "Internet Status: $int, Continue?" 10 60) then
        #Function to install Nos Software
        $(function)
    else
        #Whiptail display installetion cancel
        whiptail --title "Installation" --msgbox "The Installation has been cancel." 10 60
    fi
fi

#Save in logfile Status of internet
echo "`date -u` 'Internet Status: $int'" >> logfile.txt

关于linux - Bash Whiptail ping 进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33658935/

相关文章:

c++ - 将字节数组转换为 time_t

Linux - 将单个进程的核心利用率提取到文件中

linux - KSH:限制一次可以运行的线程数

windows - 线程 ID 与线程句柄

curl - 根据通配符条件从 Artifactory 动态下载文件

linux - 鞭尾计 : Variable in loop not being set

linux - 启动时的鞭尾

linux - wget .vs curl 使用 linux

command-line - 在 wget 之前获取文件的文件大小到 wget 吗?

linux - 对话框 显示对话框 图像配置