2
1
The following bash script is an example on how to use the dialog command. This script runs a progress bar (and displays the process upgrade). What is missing in the dialog is a time clock - that displays how much time the progress bar has been running, every second, until the end.
I am not sure if the dialog enables this, so I ask if it is possible to print the clock inside the dialog window?
If not, what are other alternatives? (for example, a clock that runs outside the dialog window)
#!/bin/bash
declare PACKAGES=("/etc/crontab" "/etc/dmtab" "/etc/fstab" "/etc/inittab" "/etc/mtab")
NUM_PACKAGES=${#PACKAGES[*]} # no. of packages to update (#packages in the array $PACKAGES)
step=$((100/$NUM_PACKAGES)) # progress bar step
cur_file_idx=0
counter=0
DEST=${HOME}
(
# infinite while loop
while :
do
cat <<EOF
XXX
$counter
$counter% upgraded
$COMMAND
XXX
EOF
COMMAND="cp ${PACKAGES[$cur_file_idx]} $DEST &>/dev/null" # sets/updates command to exec.
[[ $NUM_PACKAGES -lt $cur_file_idx ]] && $COMMAND # executes command
(( cur_file_idx+=1 )) # increase counter
(( counter+=step ))
[ $counter -gt 100 ] && break # break when reach the 100% (or greater
# since Bash only does integer arithmetic)
sleep 10 # delay it a specified amount of time i.e. 1 sec
done
) |
dialog --title "File upgrade" --gauge "Please wait..." 10 70 0
UPDATE: I also found some timer code and I want to combine this code in the dialog line - how do I do this?
The timer script (code) :
date1=` date +%s`;
while true; do
echo -ne "$(date -u --date @$((`date +%s` - $date1)) +%H:%M:%S)\r";
done
I don't believe a countdown timer is possible, as the system on which this is running is likely to be non-deterministic... – Jan – 2014-09-18T09:14:45.623