I am a beginner at Linux and a big time beginner at bash scripting. I am trying to write a bash script that will backup my home directory AND show me the progress. I found a script called bar that allows me to show a progress bar when deflating a tar.bz2 file, but not when creating one. I found your code and am trying it, but it gives me an error: lsof: no process ID specified lsof 4.81
I go your code from this page: How to add a progress bar to a shell script? Here is the code:
#! /bin/bash tar -jcf userhomeBU$(date +%Y&m&d)".tar.bz2" /home/user lsof -o0 -o -p $PID | awk ' BEGIN { CONVFMT = "%.2f" } $4 ~ /^[0-9]+r$/ && $7 ~ /^0t/ { offset = substr($7, 3) fname = $9 "stat -f %z '\''" fname "'\''" | getline len = $0 print fname, offset / len * 100 "%" } '
My home directory is backed up just fine, but I get no progress bar due to the error.
It looks like this will use the PID to watch to see when it is done. I am thinking it uses the PID and not the name of the file because the name will be unknown at the very start of the script. Can you please explain what this script is doing exactly, and why I am not getting a PID for it to watch. I have put my backup code in front and at the end but it does not show a bar, and I get the same error just at a different time.
Help!