Sample Header Ad - 728x90

Issue with bash Dialog (Whiptail) progress bar

0 votes
1 answer
1227 views
I am trying to create a bash Dialog (whiptail) progress bar for a list of commands. So, that progress bar shows along with messages when the commands get executed one by one in the background. I am using whiptail, this is a Ubuntu server, so, I am not looking at GTK based utilities that require an Xserver e.g. Zenity, Yad etc. I am very new to bash scripting and I don't know where I am getting wrong any help is appreciated. **System OS: Ubuntu 20.04** **The Issue:** > The messages are getting displayed all at once instead of stages/per > command and all the commands start executing parallelly (all at once) > instead of one by one. Is the code wrong? should I have used for loop > instead of while loop, if then how? **my list of commands:** { sudo apt-get update -y sudo apt-get install nginx -y sudo systemctl reload nginx sudo add-apt-repository ppa:ondrej/php -y sudo apt-get -y install php-fpm sudo apt-get install mariadb-server -y } **This is the code for the progress bar:** #!/usr/bin/env bash ( msgs=( "Preparing install..." "Starting Nginx installation..." "Nginx installation completed successfully" "Starting Mariadb installation..." "Starting PHP installation..." "PHP installation completed successfully" ) items=$( { #echo "Preparing install..." sudo apt-get update -y #echo "Starting Nginx installation..." sudo apt-get install nginx -y #echo "Nginx installation completed successfully" sudo systemctl reload nginx #echo "Starting Mariadb installation..." sudo apt-get install mariadb-server -y #echo "Starting PHP installation..." sudo add-apt-repository ppa:ondrej/php -y sudo apt-get -y install php-fpm #echo "PHP installation completed successfully" sudo systemctl reload nginx } | wc -l) processed=0 while [ $processed -le $items ]; do pct=$(( $processed * 100 / $items )) echo "XXX" echo $processed echo ${msgs["$processed"]} echo XXX echo "$pct" processed=$((processed+1)) sleep 1 done ) | whiptail --title "Gauge" --gauge "Please wait..." 10 60 0 **These are the messages:** msgs=( "Preparing install..." "Starting Nginx installation..." "Nginx installation completed successfully" "Starting Mariadb installation..." "Starting PHP installation..." "PHP installation completed successfully" )
Asked by depar (89 rep)
Sep 16, 2021, 08:36 PM
Last activity: Sep 17, 2021, 11:33 AM