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.
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.
Well I want to do exactly as I stated above. I ran it as it is and I like it! It reminds me of some stored procs I created in stinky windows! For right now I think this is one of those tasks that I prefer to do manually
This is what I came up with so far. I have not ran it yet but I hoped that someone would see this ode and correct any errors:
Code:
#!/bin/bash
OPTION=$(whiptail --title "Multi-Folder Compressor - By Me" --menu "Choose the month range to compress" 15 60 4 \
"0" "CANCEL" \
"1" "January to June" \
"2" "July to December" \
"3" "Specify custom month range FUTURE OPTION" \
"4" "FUTURE" 3>&1 1>&2 2>&3)
clear
YEAR=$(whiptail --inputbox "Please input the year" 10 30 3>&1 1>&2 2>&3)
#Actions to take based on selection
{
if [[ ${OPTION[1]} ]]; then
#Option 1 selected
echo "Option 1 selected"; find . -name '0101*-0631*' | xargs tar -czvf JanJun${YEAR}.tar.gz
fi
if [[ ${OPTION[2]} ]]; then
#Option 2 selected
echo "Option 2 selected"; find . -name '0701*-1231*' | xargs tar -czvf JulyDec${YEAR}.tar.gz
fi
if [[ ${OPTION[3]} ]]; then
#Option 3 selected
echo "This option is under construction"
fi
if [[ ${OPTION[4]} ]]; then
#Option 4 selected
echo "This option is for FUTURE use"
fi
if [[ ${OPTION[0]} ]]; then
#Option 5 selected
echo "You chose to cancel"
fi
}
I would like to include a progress bar if selecting option 1 or 2.
@michaelk............How do I do this? I created this from other sources and I only have limited knowledge of java which led me to what I have now. I have another script much simpler that I figured I should start out with(the 1st code I provided is much prettier 8.) )
I created several blank folders, ranging 01012017 through 12312017. There will be other folders to cover all days in a year but I only created this for a starting point. This is the SECOND OPTION of code I'm working with that is much simpler. The folders are in the same directory:
Code:
#! /bin/bash
echo "***************** Multi-folder Compressor ****************
****************** By Me **********************
Please choose an option:
1)Compress Jan to Jun
2)Compress Jul to Dec
3)FUTURE USE
4)Disabled "
read n
clear
echo "Please provide the year "
read YEAR
case $n in
1) echo "Compressing folders Jan to Jun "; find . -name '0101*-0631*' | xargs tar -cf JanJun${YEAR}.tar.gz;;
2) echo "Compressing folders Jul to Dec "; find . -name '0701*-1231*' | xargs tar -cf JulDec${YEAR}.tar.gz;;
3) echo "For future use....closing ";;
4) echo "This option is disabled ";;
*) invalid option;;
esac
I get this error:
Compressing folders Jan to Jun
tar: Cowardly refusing to create an empty archive
I'm lost. Any help is highly appreciated BUT I love that 1st code, with the pretty menu n colors n all! 8.))
@trickydba, what they are recommending is that you either use the advanced editor and properly frame code using [code][/code] tags, there are tools available in the advanced edit mode.
Further, you can also manually type these tags in, and the ones for use in LQ are located here, and discussed in the FAQ here.
Edit: Just noticed their added reply also arrived about the same time. Yes, same link.
I apologize all....
@michaelk............How do I do this? I created this from other sources and I only have limited knowledge of java which led me to what I have now. I have another script much simpler that I figured I should start out with(the 1st code I provided is much prettier 8.) )
I created several blank folders, ranging 01012017 through 12312017. There will be other folders to cover all days in a year but I only created this for a starting point. This is the SECOND OPTION of code I'm working with that is much simpler. The folders are in the same directory:
Code:
#! /bin/bash
echo "***************** Multi-folder Compressor ****************
****************** By Me **********************
Please choose an option:
1)Compress Jan to Jun
2)Compress Jul to Dec
3)FUTURE USE
4)Disabled "
read n
clear
echo "Please provide the year "
read YEAR
case $n in
1) echo "Compressing folders Jan to Jun "; find . -name '0101*-0631*' | xargs tar -cf JanJun${YEAR}.tar.gz;;
2) echo "Compressing folders Jul to Dec "; find . -name '0701*-1231*' | xargs tar -cf JulDec${YEAR}.tar.gz;;
3) echo "For future use....closing ";;
4) echo "This option is disabled ";;
*) invalid option;;
esac
I get this error:
Compressing folders Jan to Jun
tar: Cowardly refusing to create an empty archive
I'm lost. Any help is highly appreciated BUT I love that 1st code, with the pretty menu n colors n all! 8.))
Not sure if this is the exact problem; however June has only 30 days.
Hence 0631 is an invalid search term.
You probably won't get it, but "use your knuckles".
January, left, upper index knuckle = 31 days.
February, dip between index and second finger = 28/29 days.
March, next upper digit knuckle = 31 days.
...
July is the upper digit of your pinky, 31 days
Go back to the index finger, August is 31 days.
Finish the year.
Or just remember that all months alternate between 31 and 30 or the special case of February. And then remember that July/August are both 31.
Break that down. Enter the find command manually and verify that it finds the files. Combine that with your tar command. Use "set -xv" in the command line to see what the error is, also consider using that in the script. Perhaps the find command is not working or finding the correct files and thus it outputs nothing. After all, look what the error is saying.
@rtmistler......I couldn't find the issue after doing what you suggested. If you have folders created like '01012017' that go all the way to '12312017' and you wanted to tar them to one file named as such 'JanJun.tar' and 'JulDec.tar' how can this be done?
I researched doing this with files but couldn't find anything for compressing folders.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.