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.
|
|
12-23-2009, 10:06 AM
|
#1
|
LQ Newbie
Registered: Dec 2009
Location: Riga, Latvia
Distribution: Ubuntu Jaunty 9.04
Posts: 5
Rep:
|
Automated .r00 extracting bash script
Well, i red through out all the posts i possibly could finf, searched google etc, and I still can't find a solution to my painfull porblem
Heres the noobish script :
Code:
#!/bin/bash
clear;
TITLE="----------- LinRar ------------"
echo $TITLE
echo "Enter full path to your .r00 file"
read DIR
echo "Checking..."
echo
rartest="$fullDIR2rar"
if [ -e $rartest ]; then
echo
echo "Were good to go..."
echo `rar e $fullDIR2rar`
clear;
echo "|======================================|"
echo "| Thanks for using this solution...... |"
echo "|======================================|"
echo $TITLE
else
echo "Something went realy realy wrong..."
fi
What i wanted to know :- (1) How to make BASH search for .r00 file in a specific directory
(so i could change $fullDIR2rar to $dirWHEREtheRARisAT)
- (2) How to teach bash to combine founded *.r00 and the given directory in to one $FULLPATH like this - $dirWHEREtheRARisAT + $r00 into one - example : /home/user/downloads/myfilm.r00
- (3) How to insert the result $FULLPATH into RAR command so that it will extract it in the active directory, OR better if someone knows, How to Extract in a specific Directory using variables or smthing...
P.S Im a newbie in BASH'ing so your help will make me feel all fuzzy and warm inside And dont ask Why i need it... i just do, im sick and tired of many buggy r00's and that i cant extract them properly with PEAZIP or similar apps.
P.P.S Sorry for the bad english, and some code samples would be nice
Greetings from Latvia.
|
|
|
12-23-2009, 11:17 AM
|
#2
|
Senior Member
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833
Rep:
|
I'm really not quite sure what you're trying to do exactly... use unrar. There was some issues a few years back of it not working but last I tried it worked with multipart archives flawlessly as long as you specify the first file in the archive.
(Edit: I would test it myself... but I don't have a multipart archive handy... also keep in mind its usually about as easy as for i in `ls filename.r??`; do cat $i >> filename.rar; done and then unrar filename.rar even if it doesn't do multiparts)
Last edited by rweaver; 12-23-2009 at 11:24 AM.
|
|
|
12-23-2009, 11:22 AM
|
#3
|
LQ Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
|
Correct! Have used it recently and
Code:
unrar e rarfilename.rar
works flawless on my Slackware laptop. So just install unrar and you're good to go.
Kind regards,
Eric
|
|
|
12-23-2009, 11:36 AM
|
#4
|
LQ Newbie
Registered: Dec 2009
Location: Riga, Latvia
Distribution: Ubuntu Jaunty 9.04
Posts: 5
Original Poster
Rep:
|
Well, the idea is to enter the Directory where the multipart rar's are, and the then BASH does all of the dirty work...
and i think
Code:
unrar e filename.rar
works the same as
Last edited by dexitlv; 12-23-2009 at 11:39 AM.
Reason: well read it...
|
|
|
12-23-2009, 11:45 AM
|
#5
|
LQ Newbie
Registered: Dec 2009
Location: Riga, Latvia
Distribution: Ubuntu Jaunty 9.04
Posts: 5
Original Poster
Rep:
|
Quote:
Originally Posted by rweaver
[..]
(Edit: I would test it myself... but I don't have a multipart archive handy... also keep in mind its usually about as easy as for i in `ls filename.r??`; do cat $i >> filename.rar; done and then unrar filename.rar even if it doesn't do multiparts)
|
I know that i can list them, but then what ? how to make it usable further, as i said im a newbie, so a kind of a code sample could really just point in the right direction, this is my first bash script and i started only few hours ago i think 13h to be exact.
And YES i know how painfully it gets when people do not read or learn for them self, but im just asking arround, maybe someone has the time to help out...
|
|
|
12-23-2009, 11:59 AM
|
#6
|
LQ Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
|
Hi,
I think you have some errors in your script when it comes with the variables.
Code:
#!/bin/bash
clear;
TITLE="----------- LinRar ------------"
echo $TITLE
echo "Enter full path to your .r00 file"
read DIR
echo "Checking..."
echo
rartest="$fullDIR2rar"
if [ -e $rartest ]; then
echo
echo "Were good to go..."
echo `rar e $fullDIR2rar`
clear;
echo "|======================================|"
echo "| Thanks for using this solution...... |"
echo "|======================================|"
echo $TITLE
else
echo "Something went realy realy wrong..."
fi
In your code you read from userinput (read DIR) and nowhere in your script you use the DIR variable. Then you set a variable rartest to hold the value $fullDIR2rar but where do you assign that variable and what's the use for it? Next you just check if the (I suppose) directory exists and do nothing more with it. And why would you use echo with backticks to execute a command in bash when you can just type it? Those are some pointers. Taking into account the above I took the liberty of changing your script to what's below, keeping it basic and simple without loops so you can learn from it. When writing scripts, keep them lined out correctly, it'll improve readability.
Code:
#!/bin/bash
clear;
TITLE="----------- LinRar ------------"
echo $TITLE
echo "Enter full path to your .r00 file"
read DIR
echo "Checking..."
echo ""
if [ -e $DIR ]; then
echo ""
echo "Were good to go..."
echo ""
cd $DIR
rar e *.rar
clear;
echo "|======================================|"
echo "| Thanks for using this solution...... |"
echo "|======================================|"
echo $TITLE
else
echo "Something went realy realy wrong..."
fi
Kind regards,
Eric
|
|
|
12-23-2009, 12:17 PM
|
#7
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by dexitlv
What i wanted to know :- (1) How to make BASH search for .r00 file in a specific directory
(so i could change $fullDIR2rar to $dirWHEREtheRARisAT)
- (2) How to teach bash to combine founded *.r00 and the given directory in to one $FULLPATH like this - $dirWHEREtheRARisAT + $r00 into one - example : /home/user/downloads/myfilm.r00
- (3) How to insert the result $FULLPATH into RAR command so that it will extract it in the active directory, OR better if someone knows, How to Extract in a specific Directory using variables or smthing...
|
- I don't understand the question. Your English is clear but your meaning is not. "$fullDIR2rar" is almost certainly not what you want it to be; it is the value of a variable called $fullDIR2rar but the only variable with a value is $DIR. For debugging, you can use set -xv to trace what the shell is doing (and set +xv to turn it off) so this would help
Code:
set -xv
rartest="$fullDIR2rar"
set +xv
In case you find the set -xv output too much you could use something like
Code:
rartest="$fullDIR2rar"
echo "DEBUG: rartest is '$rartest'"
If you want to find .r00 files in the current directory and its subdiectories, you can use
Code:
find . -iname '*.r00'
- When you say "teach" do you mean "tell"? The find command above will generate the full path of all *.r00 files, one per line. There are many threads in LQ about using the find command in bash. Some of them are listed here.
- How about copying the .r00 file to where you want the extracted files to go, unrar it and then delete the copy of the .r00 file?
EDIT: or you could try creating a symbolic link to the .r00 file from the target directory and then unrar that
Code:
cd <target directory>
ln -s <source directory>/<something.r00> <something.r00>
unrar <something.r00>
Last edited by catkin; 12-23-2009 at 12:21 PM.
Reason: Added missing '." in the find pattern
|
|
|
12-23-2009, 02:25 PM
|
#8
|
Senior Member
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833
Rep:
|
The full code for a bash script that cat them into one file would be more or a less the for loop i posted plus "&& unrar e filename"
|
|
|
12-23-2009, 03:19 PM
|
#9
|
LQ Newbie
Registered: Dec 2009
Location: Riga, Latvia
Distribution: Ubuntu Jaunty 9.04
Posts: 5
Original Poster
Rep:
|
Quote:
Originally Posted by rweaver
The full code for a bash script that cat them into one file would be more or a less the for loop i posted plus "&& unrar e filename"
|
Could you please post the link ?
|
|
|
01-15-2010, 01:58 AM
|
#10
|
LQ Newbie
Registered: Dec 2009
Location: Riga, Latvia
Distribution: Ubuntu Jaunty 9.04
Posts: 5
Original Poster
Rep:
|
Okay i finally made it
It has a clan-up feature too
Code:
#!/bin/bash
#
# İİ Some rights reserved. This work is licensed under a
# Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.
#
# Izveidoja: Rihards 'dExIT' Mantejs
# Versija : 0.35
# Info : www.geex.lv / geex.raksta.lv
# Twitter : geexlv
# Mail : dexit@geex.lv
#
# Autortiesības : http://creativecommons.org/licenses/by-nc-sa/3.0/
#
# Paldies saku : Geir 'geirha' Hauge, Neil '\amethyst' Moore
#
# Programma domāta kad norāda mapi kur atrodas .r** faili un ekstrakto tos
#
while true; do
if dir=$(zenity --title="LinRAR by dExIT" --file-selection --directory); then
if [[ ! -d $dir ]]; then
echo "$dir: Wrong Directory" >&2
else
( cd "$dir" && for f in *.r00; do [[ -f $f ]] || continue; rar e "$f" && rm "${f%00}"[0-9][0-9]; done )
fi
else
echo "$bold Selection cancelled $bold_off" >&2
exit 1
fi
zenity --title="Givem to meh...?" --question --text="More work sire?" || break
done
|
|
|
All times are GMT -5. The time now is 04:52 PM.
|
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
|
|