I'm trying to create a progress bar or some sort of loading icon to show that a hash is being created, instead of a blank screen with nothing happening... This is what I have so far:
if [[ $hashing != "y" && $hashing != "Y" ]]; then
echo -e "\n"
sudo dd if=dev/"$source" | md5sum
read -r compareresult
i=1
sp="/-\|"
echo -n ' '
while true
do
printf "\b${sp:i++%${#sp}:1}"
done
exit
fi ;;
This uses a spinning wheel to represent a loading icon. And it does work using what's above. But doesn't at the moment? Not sure if the order is incorrect or if I'm missing something. Any help would be great thanks
#!/bin/bash
#Clone_Command
while true
do
sudo -s
echo "==========================="
echo " Clone Command "
echo "==========================="
echo -e "\n"
echo -e "\n"
echo "Enter 1 for source device"
echo "Enter 'a' to hash source device"
echo "Enter 2 for destination device"
echo "Enter 3 to list all available disks"
echo "Enter 4 to execute dd command"
echo "Enter 5 to compare MD5 hashes"
echo "Enter q to exit"
echo -e "\n"
echo "PLEASE NOTE LISTING ALL DISKS WILL REQUIRE YOU TO RELOAD THE SCRIPT"
echo -e "\n"
echo -e "Enter your choice \c"
read -r choice
case "$choice" in
q) exit;;
1) echo -e "Enter source device '/dev/---'
Enter the last 3 letters of the device eg - sdf or sdb etc"
read -r source ;;
a) echo -e "Hashing this device may take a while depending on size"
echo -e "\n"
echo -e "Press enter if you wish to hash this device"
read -r hashing
if [[ $hashing != "y" && $hashing != "Y" ]]; then
echo -e "\n"
sudo dd if=dev/"$source" | md5sum
read -r compareresult
i=1
sp="/-\|"
echo -n ' '
while true
do
printf "\b${sp:i++%${#sp}:1}"
done
exit
fi ;;
2) echo -e "Enter destination device '/dev/---'
Enter the last 3 letters of the device eg - sdf or sdb etc"
read -r destination ;;
3) echo -e "Press enter to list all available disks \c"
read -r answ
if [[ $answ != "y" && $answ != "Y" ]]; then
clear
sudo lshw -class disk
exit
fi ;;
4) echo -e "This will format $destination. If you wish to continue press enter \c"
read -r ans
if [[ $ans != "y" && $ans != "Y" ]]; then
echo -e "\n"
sudo dd if=/dev/"$source" of=/dev/"$destination" bs=4096 status=progress
exit
fi ;;
5) echo -e "If you wish to compare MD5 Hash of both USBs then press 'Enter'\c"
read -r compare
if [[ $compare != "y" && $compare != "Y" ]]; then
echo -e "\n"
echo -e "Please note this is not a quick process"
echo -e "n"
md5sum -c <<<"$compareresult /dev/$destination"
fi ;;
esac
done
compareresult
? -- The spinner starts after md5sum has finished. I suggest to put it into the background (with&
) and check for the process to finish or put the spinner into the background. -- An alternative is to create an image file (maybe that's what you want anyway) and then runmd5sum
on that file. -- Another alternaitve is to usepv
(progress view) instead ofdd
. – sudodus Nov 17 '21 at 14:23compareresult
would take the created md5 hash of the whole USB to verify against the cloned USB stick, which I don't think it doesn't do lol. With regards to putting the spinner in the background where would I add this? I'll add the whole script as well to make it easier to understand. – cameron.g Nov 17 '21 at 14:30