2015-11-11 60 views
0

我正在嘗試使用Whiptail製作一個進度條,它可以正確跟蹤wget ping的進度。Bash Whiptail 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 
+0

這裏沒有問題,因爲這樣的(僅適用於如何將wget的輸出一個隱含的要求轉換成可以傳送到量具小部件的數據)。 –

+0

這更像是一個如何猜測:P –

+0

是的......但確定百分比很難,因爲wget並沒有將其作爲其進展的一部分予以宣傳。 –

回答

2

我發現,工作
更新的解決方案的方式

#!/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