LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-13-2017, 02:34 PM   #1
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Rep: Reputation: Disabled
Progress bar


I have a script that compresses either Jan-Jun folders that contain reports or Jul-Dec. I would like to incorporate a progress bar. Any help is highly appreciated. This is my code:
Code:
#!/bin/bash

OPTION=$(whiptail --title "Multi-Folder Compressor - By Me " --menu "Choose the month range to compress" 15 60 4 \
"1" "January to June" \
"2" "July to December" \
"3" "FUTURE"  3>&1 1>&2 2>&3)

YEAR=$(whiptail --inputbox "Please input the year" 10 30 3>&1 1>&2 2>&3)

#Actions to take based on selection
case $OPTION in
    1) echo "Compressing folders Jan to Jun "; find . -type d \( -name "01*" -o -name "02*" -o -name "03*" -o -name "04*" -o -name "05*" -o -name "06*" \) | xargs tar -zcvf /export/dir/dir/reports/dir/dir/JanJun${YEAR}.tar.gz;;
    2) echo "Compressing folders Jul to Dec "; find . -type d \( -name "07*" -o -name "08*" -o -name "09*" -o -name "10*" -o -name "11*" -o -name "12*" \) | xargs tar -zcvf /export/dir/dir/reports/dir/dir/JulDec${YEAR}.tar.gz;;
    3) echo "For future use....closing ";;
    4) echo "This option is disabled ";;
    *) invalid option;;

esac
 
Old 01-13-2017, 03:08 PM   #2
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 987

Rep: Reputation: 260Reputation: 260Reputation: 260
Although I've never tried this, it was designed to show dd progress, dd was replaced with tar in the code below.

Code:
ps ux | awk '/bin\/tar/ && !/awk/ {print $2}' | xargs kill -s USR1 $1

Last edited by Brains; 01-13-2017 at 05:22 PM.
 
2 members found this post helpful.
Old 01-13-2017, 03:21 PM   #3
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Where do I plug this in my code?
 
Old 01-13-2017, 03:27 PM   #4
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I am looking to incorporate something like this example in my code:
Code:
#!/bin/bash
PCT=0
(
while test $PCT != 100;
do
PCT=`expr $PCT + 10`;
echo $PCT;
sleep 1;
done; ) | whiptail --title "GAUGE" --gauge "Hi, this is a gauge widget" 20 70 0
 
Old 01-13-2017, 04:34 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,526

Rep: Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137
You can use the pv command to pass values to whiptail but if you want something realistic you need to find the total size of all directories to be tarred via the du command.

Here is an example using pv to monitor progress without whiptail.
Code:
find . -type d \( -name "01*" -o -name "02*" -o -name "03*" -o -name "04*" -o -name "05*" -o -name "06*" \) | pv  -s total_number_of_bytes | xargs tar -zcvf file_name.tgz
Untested but something like this might work
Code:
find . -type d \( -name "01*" -o -name "02*" -o -name "03*" -o -name "04*" -o -name "05*" -o -name "06*" \) | (pv  -n -s no_of_bytes | xargs tar -zcvf testme.tgz) | whiptail --title "GAUGE" --gauge "Hi, this is a gauge widget" 20 70 0
 
1 members found this post helpful.
Old 01-17-2017, 08:03 AM   #6
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
This 'pv', is this something that comes with the install or I have to get it installed?
Where do I incorporate this in my script?
I'm want to add this in my script mainly to shine it up a bit. To make it look like I know what I'm doing, LOL.

Last edited by trickydba; 01-17-2017 at 08:04 AM.
 
Old 01-17-2017, 08:49 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,526

Rep: Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137
Should be installed. My example was complete for taring jan-Jun files
 
1 members found this post helpful.
Old 01-17-2017, 09:01 AM   #8
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@michaelk......Where do I exactly plug in this code?
 
Old 01-17-2017, 09:02 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,526

Rep: Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137
Your option 1
 
1 members found this post helpful.
Old 01-17-2017, 09:45 AM   #10
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I plugged in your suggested code, and it ran, but after selecting the option and inputting the year nothing happens. The script stops. Here is the actual code:
Code:
#!/bin/bash

OPTION=$(whiptail --title "Multi-Folder Compressor - By Me " --menu "Choose the month range to compress" 15 60 4 \
"1" "January to June" \
"2" "July to December" \
"3" "FUTURE"  3>&1 1>&2 2>&3)

YEAR=$(whiptail --inputbox "Please input the year" 10 30 3>&1 1>&2 2>&3)

#Actions to take based on selection
case $OPTION in
        1) find . -type d \( -name "01*" -o -name "02*" -o -name "03*" -o -name "04*" -o -name "05*" -o -name "06*" \) | (pv  -n -s no_of_bytes | xargs tar -zcvf /dir1/dir2/dir3/dir4/dir5/reports/JanJun${YEAR}.tar.gz) | whiptail --title "GAUGE" --gauge "Hi, this is a gauge widget" 20 70 0

        2) find . -type d \( -name "07*" -o -name "08*" -o -name "09*" -o -name "10*" -o -name "11*" -o -name "12*" \) | (pv  -n -s no_of_bytes | xargs tar -zcvf /dir1/dir2/dir3/dir4/dir5/reports/JanJun${YEAR}.tar.gz) | whiptail --title "GAUGE" --gauge "Hi, this is a gauge widget" 20 70 0

        3) echo "For future use....closing ";;
        4) echo "This option is disabled ";;
        *) invalid option;;

esac
 
Old 01-17-2017, 09:46 AM   #11
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
I thought it would be because there wasn't ";;" after option 1 and 2 but that did nothing.
 
Old 01-17-2017, 10:02 AM   #12
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,583

Rep: Reputation: 4344Reputation: 4344Reputation: 4344Reputation: 4344Reputation: 4344Reputation: 4344Reputation: 4344Reputation: 4344Reputation: 4344Reputation: 4344Reputation: 4344
insert set -xv at the beginning of your script and you will see what's happening (this will not solve anything, just print variables and program flow).
 
1 members found this post helpful.
Old 01-17-2017, 10:29 AM   #13
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
Says a ")" is missing but I don't see one missing
 
Old 01-17-2017, 04:00 PM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,526

Rep: Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137Reputation: 3137
I did mislead you in the fact that what I posted was not working code. As stated to be a meaningful percentage you need to find the number of bytes to be tarred. The following might work as an approximation.

Code:
bytes=$(find . -type d \( -name "01*" -o -name "02*" -o -name "03*" -o -name "04*" -o -name "05*" -o -name "06*" \) -exec du -cb {} + | grep total$ | awk '{print $1}')
That is your no_of_bytes variable for your script. As an exercise can you add the above into your script?
 
1 members found this post helpful.
Old 01-18-2017, 10:52 AM   #15
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@michaelk.....After inputting your code:
Code:
echo "Compressing folders Jan to Jun "; bytes=$(find . -type d \( -name "01*" -o -name "02*" -o -name "03*" -o -name "04*" -o -name "05*" -o -name "06*" \) -exec du -cb {} + | grep total$ | awk '{print $1}')
I get this error:
Code:
./compressfolderfinal: line 13: syntax error near unexpected token `)'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mv with progress bar gbowden Linux - General 28 08-14-2013 05:42 AM
cp progress bar edwardsiow Linux - General 26 09-04-2011 09:53 AM
cp with progress bar? Rotwang Linux - General 5 04-27-2005 08:49 PM
cp: progress bar chii-chan Linux - General 2 10-30-2003 07:30 PM
Progress Bar zael Programming 3 10-01-2003 01:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration