Linux Bash鞭击ping进度条

Linux Bash鞭击ping进度条,linux,wget,whiptail,Linux,Wget,Whiptail,我正在尝试使用Whiptail制作一个进度条,它可以正确跟踪wget ping的进度 我的目标是创建一个脚本,通过ping到google.com来测试你的互联网,在这个过程中,它会显示你使用whiptail的进度,然后,如果你上网,它会向你发送一个msgbox,否则它会显示一个yes或no whiptail,询问你是否继续 我目前的尝试: #!/bin/bash #Make ping and display proces #Progres bar GUI us

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

我的目标是创建一个脚本,通过ping到google.com来测试你的互联网,在这个过程中,它会显示你使用whiptail的进度,然后,如果你上网,它会向你发送一个msgbox,否则它会显示一个yes或no 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

这里没有这样的问题(只是一个关于如何将wget的输出转换为可以通过管道传输到gauge小部件的数据的隐含请求)。。。但确定百分比很难,因为wget并没有将其作为其进展的一部分进行宣传。是的,我想。。。这就是为什么我把它改为ping,让它一个接一个地运行