Linux - NewbieThis 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.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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
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.
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.
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
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).
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.