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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
01-13-2017, 01:34 PM
|
#1
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Rep: 
|
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
|
|
|
01-13-2017, 02:08 PM
|
#2
|
Senior Member
Registered: Apr 2009
Distribution: All OS except Apple
Posts: 1,591
|
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 04:22 PM.
|
|
2 members found this post helpful.
|
01-13-2017, 02:21 PM
|
#3
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
Where do I plug this in my code?
|
|
|
01-13-2017, 02:27 PM
|
#4
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
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
|
|
|
01-13-2017, 03:34 PM
|
#5
|
Moderator
Registered: Aug 2002
Posts: 26,906
|
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.
|
01-17-2017, 07:03 AM
|
#6
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
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 07:04 AM.
|
|
|
01-17-2017, 07:49 AM
|
#7
|
Moderator
Registered: Aug 2002
Posts: 26,906
|
Should be installed. My example was complete for taring jan-Jun files
|
|
1 members found this post helpful.
|
01-17-2017, 08:01 AM
|
#8
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
@michaelk......Where do I exactly plug in this code?
|
|
|
01-17-2017, 08:02 AM
|
#9
|
Moderator
Registered: Aug 2002
Posts: 26,906
|
Your option 1
|
|
1 members found this post helpful.
|
01-17-2017, 08:45 AM
|
#10
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
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
|
|
|
01-17-2017, 08:46 AM
|
#11
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
I thought it would be because there wasn't ";;" after option 1 and 2 but that did nothing.
|
|
|
01-17-2017, 09:02 AM
|
#12
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,640
|
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.
|
01-17-2017, 09:29 AM
|
#13
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
Says a ")" is missing but I don't see one missing
|
|
|
01-17-2017, 03:00 PM
|
#14
|
Moderator
Registered: Aug 2002
Posts: 26,906
|
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.
|
01-18-2017, 09:52 AM
|
#15
|
Member
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310
Original Poster
Rep: 
|
@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 `)'
|
|
|
All times are GMT -5. The time now is 01:24 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|