[Answered] The method that I went with that works and is beginner friendly, I simply added the
# Progress Bar
echo -n 'Progress: [--------------------]'
sleep 1 # <- Command 1
echo -ne '\rProgress: [#####---------------]'
sleep 1 # <- Command 2
echo -ne '\rProgress: [##########----------]'
sleep 1 # <- Command 3
echo -ne '\rProgress: [###############-----]'
sleep 1 # <- Command 4
echo -e '\rProgress: [####################]'
right before the print the end status message and it works like a charm for this situation; testing purposes and getting a feel for it. Hopefully, this helps anyone else in the future.
I've looked over the forums and posts but it seems as though most of them include having to install additional addons to inject a progress bar. I'm new to scripting and trying to learn and thought this would be a great addition to a simple script.
I understand how to use pv to add a progress update but it requires installation before it would work. Which is completely opposite of what I'm wanting.
Is there not a way to use the same progress bar that's built into linux when updating your system or installing applications like in the image below (for example)
And the script I'm wanting to add the simple progress bar without any additional installations for the users.
#!/bin/bash
### Title: Archive and backup script
### Date: 16 July 2022
### Author: CJG
### Version: 1.0.0
# The path of the folder you want to back up (change to folder of choice)
backup_files="/home/"
# The backup destination path (change from tmp otherwise it will be deleted upon system reboot)
dest="/tmp"
# Create a variable for the start and end times
# date command will take the current time when the now variable is called
# %H will format output to show the hour when variable is called
# %M will format output to show the minutes when variable is called
# %S will format output to show the seconds when the variable is called
now=$(date +"%H:%M:%S")
# Create the archive filename
currentDate=$(date +"%y-%m-%d")
hostname=$(hostname -s)
archive_file="$hostname-$currentDate.tgz"
# Inform that the process is starting
echo "Backing up $backup_files to $dest/$archive_file"
echo "The process is starting."
# Print the start time
echo Script start time: "$now"
# Back up the files using the tar command
tar -czPf $dest/$archive_file $backup_files
# Print the end status message
echo "Backup Is Complete"
now=$(date +"%H:%M:%S")
echo Script end time: "$now"