You are not logged in.

#1 2012-04-29 10:07:43

UFOKatarn
Member
Registered: 2010-08-29
Posts: 30

multiarchive RAR bash script (SOLVED)

Dear Fellow Archies!

I use the command

rar a -w<working_folder> -m5 -v<max_volume_size> <archive_name> <target_file_or_folder>

whenever I need to make a multiarchive rar file, because I have not yet found a GUI archive manager that does this.

So, I've decided to write a simple bash script to make things easier.

Here's the script:

#!/bin/bash
echo Please, enter the full path to the target file or folder [without the target itself]!
read PATH
echo Please, enter the target filename [with extension] or folder name!
read TARGET
echo Please, enter the desired archive name [without extension]!
read DESTINATION
echo Please, enter the desired volume size in KB!
read SIZE
rar a -w$PATH -m5 -v$SIZE $DESTINATION $TARGET

Executing the last line of the code in terminal works without any hassle. When I run this entire script however, it doesn't.

What needs to be changed for the script to work?

RAR man page is HERE - CLICK, in case someone needs to take a look at something.

Thank you and thank you,
UFOKatarn

Last edited by UFOKatarn (2012-05-03 07:38:28)

Offline

#2 2012-04-30 17:18:08

juster
Forum Fellow
Registered: 2008-10-07
Posts: 195

Re: multiarchive RAR bash script (SOLVED)

PATH is a special variable in shell scripting. The value of PATH tells the shell which directories to search for executables when running an external command such as rar.

Offline

#3 2012-05-02 09:15:39

UFOKatarn
Member
Registered: 2010-08-29
Posts: 30

Re: multiarchive RAR bash script (SOLVED)

Juster: Thank you for the answer. I renamed "PATH" and "$PATH" to "LOCATION" and "$LOCATION", but it still didn't work. So my guess is that after "read" and after "$", what is physically written doesn't matter, even if the text following these two commands is normally used as a command on it's own.

My guess would be that the problem lies in those shell tricks where the process instance "escapes" from she shell and is executed on its own, without the correct path where you want the script to run.

Any thoughts?

Thanks again,
UFOKatarn

Offline

#4 2012-05-02 18:29:28

juster
Forum Fellow
Registered: 2008-10-07
Posts: 195

Re: multiarchive RAR bash script (SOLVED)

Why do you think it doesn't work? What do you consider working? Please post the bad output of the script and maybe even the good output of the command. Run the script with bash -x or add -x to the shebang line to see what is being run.

Offline

#5 2012-05-02 19:06:21

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: multiarchive RAR bash script (SOLVED)

Make sure to quote the location variable, since read picks up on spaces, but bash expansion does not. First space it encounters, if bash is concerned, is the end of your variable's value.


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#6 2012-05-02 19:41:09

UFOKatarn
Member
Registered: 2010-08-29
Posts: 30

Re: multiarchive RAR bash script (SOLVED)

Wow, I didn't know about the "-x" switch!

And by "it doesn't work", I meant that no archive file is produced by the script.

Thank you both! smile

So, after running the "multirar" script, I found out that the "rar" command is not recognized (see last line of output). How? Why?

bash -x multirar 
+ echo Please, enter the full path to the target file or folder '[without' the target 'itself]!'
Please, enter the full path to the target file or folder [without the target itself]!
+ read LOCATION
/home/ufokatarn/
+ echo Please, enter the target filename '[with' 'extension]' or folder 'name!'
Please, enter the target filename [with extension] or folder name!
+ read TARGET
testfile.pdf
+ echo Please, enter the desired archive name '[without' 'extension]!'
Please, enter the desired archive name [without extension]!
+ read DESTINATION
testarchive
+ echo Please, enter the desired volume size in 'KB!'
Please, enter the desired volume size in KB!
+ read SIZE
100000
+ rar a -w/home/ufokatarn/ -m5 -v100000 testarchive testfile.pdf
multirar: line 10: rar: command not found

Any ideas?

Last edited by UFOKatarn (2012-05-02 19:42:14)

Offline

#7 2012-05-02 20:07:36

geniuz
Member
Registered: 2010-04-10
Posts: 127

Re: multiarchive RAR bash script (SOLVED)

My guess is your original program (i.e. with the read PATH) overwrote the original $PATH variable set by the shell by default. Try opening a new terminal or if that doesn't work, re-login.

Offline

#8 2012-05-02 20:20:48

juster
Forum Fellow
Registered: 2008-10-07
Posts: 195

Re: multiarchive RAR bash script (SOLVED)

rar is not being located in the script's currently active PATH. Check to make sure PATH is set properly in the script (add a line of: echo "$PATH"). If not, either add the directory containing rar to PATH or move rar to a standard location. Working from the other direction, check to see if the successful call to rar has a different PATH than your script.

If rar is in the current directory, then . (a period) must be in your PATH in order for the shell to search the current directory for commands. An empty entry means the same thing as a period.

Offline

#9 2012-05-03 07:36:57

UFOKatarn
Member
Registered: 2010-08-29
Posts: 30

Re: multiarchive RAR bash script (SOLVED)

Done! Working!

Geniuz: Logout-login did it. How simple. smile

Juster: I added "echo $PATH" to the script and ran it with "bash -x". And the output was the same as after the logout-login. Here it is, in case you are curious.

/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl:/opt/qt/bin

Thank you all for your help guys :bow:.

-------

OFFTOPIC:

All who intend to use Xfce launchers to run bash scripts: There are two options in the settings for each launcher: "Command" and "Working Directory". And when I had "Working Directory" filled with "/home/username/", the script didn't work. It worked perfectly after I blanked out the "Working Directory" option. Just so you know, in case someone doesn't smile.

This has never happened to be before, but still, I guess it is better to do it with blank "Working Directory" and entering the entire path into the script in the "Command" field. It might be that Xfce launchers always stick to the "Working Directory", even though a script might tell them otherwise.

Last edited by UFOKatarn (2012-05-03 07:38:05)

Offline

Board footer

Powered by FluxBB