LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-23-2009, 10:06 AM   #1
dexitlv
LQ Newbie
 
Registered: Dec 2009
Location: Riga, Latvia
Distribution: Ubuntu Jaunty 9.04
Posts: 5

Rep: Reputation: 0
Talking 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.
 
Old 12-23-2009, 11:17 AM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
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.
 
Old 12-23-2009, 11:22 AM   #3
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
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
 
Old 12-23-2009, 11:36 AM   #4
dexitlv
LQ Newbie
 
Registered: Dec 2009
Location: Riga, Latvia
Distribution: Ubuntu Jaunty 9.04
Posts: 5

Original Poster
Rep: Reputation: 0
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
Code:
rar e filename.rar

Last edited by dexitlv; 12-23-2009 at 11:39 AM. Reason: well read it...
 
Old 12-23-2009, 11:45 AM   #5
dexitlv
LQ Newbie
 
Registered: Dec 2009
Location: Riga, Latvia
Distribution: Ubuntu Jaunty 9.04
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rweaver View Post
[..]
(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...
 
Old 12-23-2009, 11:59 AM   #6
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Arrow

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
 
Old 12-23-2009, 12:17 PM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by dexitlv View Post
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...
  1. 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'
  2. 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.
  3. 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
 
Old 12-23-2009, 02:25 PM   #8
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
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"
 
Old 12-23-2009, 03:19 PM   #9
dexitlv
LQ Newbie
 
Registered: Dec 2009
Location: Riga, Latvia
Distribution: Ubuntu Jaunty 9.04
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rweaver View Post
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 ?
 
Old 01-15-2010, 01:58 AM   #10
dexitlv
LQ Newbie
 
Registered: Dec 2009
Location: Riga, Latvia
Distribution: Ubuntu Jaunty 9.04
Posts: 5

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


Reply

Tags
bash, rar


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
My Linux Bash Script Fails to run when automated with OS Startup sanitynotvanity Linux - Software 5 06-16-2009 11:50 AM
Bash automated testing anonguy9 LinuxQuestions.org Member Success Stories 0 03-29-2009 07:13 PM
Extracting "Hours" from uptime in a BASH script? BassKozz Linux - General 16 02-17-2009 09:15 PM
Automated build and email log in bash sardaukar_siet Linux - Server 1 03-08-2007 12:59 PM
Automated su script? elmetald00d Linux - General 5 04-09-2002 12:17 AM

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

All times are GMT -5. The time now is 04:52 PM.

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