LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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-11-2017, 05:36 PM   #16
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled

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

Last edited by trickydba; 01-11-2017 at 05:38 PM.
 
Old 01-12-2017, 07:46 AM   #17
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
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.

Last edited by trickydba; 01-12-2017 at 12:16 PM.
 
Old 01-12-2017, 09:06 AM   #18
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
At first glance OPTION is not an array and you might want to specify the full path to your search directory and tar.gz file.

I have not played with whiptail much so can not help with its gauge box.
 
1 members found this post helpful.
Old 01-12-2017, 09:19 AM   #19
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@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.))

Last edited by trickydba; 01-12-2017 at 12:18 PM.
 
Old 01-12-2017, 09:30 AM   #20
jamison20000e
Senior Member
 
Registered: Nov 2005
Location: ...uncanny valley... infinity\1975; (randomly born:) Milwaukee, WI, US( + travel,) Earth&Mars (I wish,) END BORDER$!◣◢┌∩┐ Fe26-E,e...
Distribution: any GPL that work on freest-HW; has been KDE, CLI, Novena-SBC but open.. http://goo.gl/NqgqJx &c ;-)
Posts: 4,888
Blog Entries: 2

Rep: Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567
Post

I can recommend [CODE][QUOTE][/QUOTE][/CODE] [B]tags![/B]
Code:
eg
 
1 members found this post helpful.
Old 01-12-2017, 09:31 AM   #21
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@jamison200003.........what is that? Where do I plug it in?
 
Old 01-12-2017, 09:35 AM   #22
jamison20000e
Senior Member
 
Registered: Nov 2005
Location: ...uncanny valley... infinity\1975; (randomly born:) Milwaukee, WI, US( + travel,) Earth&Mars (I wish,) END BORDER$!◣◢┌∩┐ Fe26-E,e...
Distribution: any GPL that work on freest-HW; has been KDE, CLI, Novena-SBC but open.. http://goo.gl/NqgqJx &c ;-)
Posts: 4,888
Blog Entries: 2

Rep: Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567
Quote:
Originally Posted by trickydba View Post
@jamison200003.........what is that? Where do I plug it in?
I forget the quick keys but if you hit "go advanced" here you get more LQ editor options to clarify your text with...
 
1 members found this post helpful.
Old 01-12-2017, 09:39 AM   #23
jamison20000e
Senior Member
 
Registered: Nov 2005
Location: ...uncanny valley... infinity\1975; (randomly born:) Milwaukee, WI, US( + travel,) Earth&Mars (I wish,) END BORDER$!◣◢┌∩┐ Fe26-E,e...
Distribution: any GPL that work on freest-HW; has been KDE, CLI, Novena-SBC but open.. http://goo.gl/NqgqJx &c ;-)
Posts: 4,888
Blog Entries: 2

Rep: Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567
Here we go: http://www.linuxquestions.org/questi....php?do=bbcode
 
1 members found this post helpful.
Old 01-12-2017, 09:42 AM   #24
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Excellent point jamison20000e.

@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.
 
1 members found this post helpful.
Old 01-12-2017, 09:44 AM   #25
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
All I implied is that whiptail does not return an array so instead of ${OPTION[x]} you would use $OPTION.

The case syntax is not correct in your second script. You need to use ;; to separate each items code.

There are many ways to create menus with or without a window.
 
1 members found this post helpful.
Old 01-12-2017, 12:15 PM   #26
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
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.))
 
Old 01-12-2017, 12:35 PM   #27
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
 
1 members found this post helpful.
Old 01-12-2017, 12:56 PM   #28
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
This is my final code:

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
case $OPTION in
    1) echo "Compressing folders Jan to Jun "; find . -name '0101*-0630*' | 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
and I get this error:
Code:
Compressing folders Jan to Jun
tar: Cowardly refusing to create an empty archive
I chose #1

Last edited by trickydba; 01-12-2017 at 12:57 PM.
 
Old 01-12-2017, 01:02 PM   #29
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
 
1 members found this post helpful.
Old 01-12-2017, 02:18 PM   #30
trickydba
Member
 
Registered: Nov 2016
Location: Atlanta,Georgia
Posts: 310

Original Poster
Rep: Reputation: Disabled
@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.
 
  


Reply



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
logrotate compress files after 7 days and keep them for two months. mariogarcia Ubuntu 4 12-13-2013 08:29 AM
Shell Script to compare folders,Sub-Folders and Sub-Sub-Folders unix_72427 Programming 8 08-08-2012 02:51 PM
Loop mounting compressed folders: which ones are safe to compress? mahkoe Linux - General 1 12-13-2011 03:13 PM
bash script to create folders including making recursive folders.... linux-bandit Linux - Software 8 11-28-2009 01:50 AM
find -exec command to recursively delete files and folders in folders with X name Joan Murt Linux - Newbie 2 07-08-2009 04:35 PM

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

All times are GMT -5. The time now is 04:13 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
Open Source Consulting | Domain Registration