Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
script 2 (compress_all.sh):
---------------------------------
#! /bin/sh
sh -x compress.sh 1999 103 a password
I get a message that RAR can't find the source files to add in the archiv. With the -x I have the output on screen, I'm surprised about the quotes (!!??)
`/opt/rar/rar_static a -s -rr8 -cl -hppassword -m5 ../index/rar/1999/1999.103.01.rar` ../index/bmp/1999/1999.103*.bmp
Does the command work when you replace the variables and run it from the command line. I'm not at a box with rar on it just now but I think you may need to place the a switch before the files to be added - If that doesn't work I'll try and download rar to this box.
nop, the command line is ok, because when I type it in (means $/opt/rar ...... etc) than its working. I'm realy sure that something wrong with the script, variables or replacing - but I don't know where (I'm not so familiar with shell scripts). The RAR is licenced and it's working fine on command line, but I need the scripts because I have thousands of pictures ;-)
#!/bin/sh
# Command together with all switches. Notice pass is here,
# on my box (old rar-2.9) the switch is "-p<pass>"
rar_opt="a -s -rr1024 -cl -m5i -r0 -p"$1""
# Expecting 3 args: pass, /path/to/src, lame_wildcard
case "$#" in 3) ;; *) exit 1;; esac
# Unfsck 4th level rardir and make it if it ain't there
src=( $(echo $2 | tr "/" " ") )
base="/${src[0]}/${src[1]}/${src[2]}"; rardir="${base}/rar"
if [ ! -d "${rardir}" ]; then mkdir -p "${rardir}"; fi
# Filename, really lame based on bare "$3"
rarfile="${rardir}/$3.rar"
# This is really BAD advise, but...
files=$(find "$2" -type f -name $3\*.bmp)
# If we have files do something
case "${#files}" in 0) exit 1;; *) rar ${rar_opt} "${rarfile}" "${files}";; esac
So this looks from the commandline like "(sh -x) rar_compress.sh pass /data/pictures/index/bmp/1999 1999.103"
which should yield /data/pictures/index/rar/1999.103.rar
Note I didn't put in a sequence number (1999.103.01.rar) like you posted in yer first thread and almost NO input validation is done for spaces, weird chars etc etc so YMMV(VM).
First of all, I used your script, deleted some mistakes and it's running well. But the call of RAR gives me the same error. I'm 100% sure that the mistake is the line
/opt/rar/rar ${rarofp} "${rarfile}" "${files}"
or my native version. The output with "sh -x ..." says that no rarfile and files is set. But the previous "find" command can find the files. Means the variables are ok. When I replace the rarfile variable with /data/pictures/index/rar/1999.103.rar than RAR can create the archives but can't find the BMP files.
I thought may be the RAR has a problem and replaced the version with a previous one, but the same result. My system is a SuSE 7.3 and SH version 2.05.
It's very funny and I get very angry against shell programming. I waste my time with a stupid small command. I made it many time under DOS or NT, but this is definitely whorse.
The output with "sh -x ..." says that no rarfile and files is set.
Show it, instead of talking about it.
But the previous "find" command can find the files. Means the variables are ok.
Nope. Means the files are there.
When I replace the rarfile variable with /data/pictures/index/rar/1999.103.rar than RAR can create the archives but can't find the BMP files.
Have you tried using full paths like David_ross asked in his first reply?
It's very funny and I get very angry against shell programming.
Hmm. I don't. I usually know it's me who's making the mistakes. Ever heard of the GIGO principle? :-]
The option -hp in RAR is a new option and ecrypt the file and the filelist in the archive.
I attach the new script:
#!/bin/sh
rar_opt="a -s -rr1024 -cl -m5 -r0 -hp"$1""
src=( $(echo $2 | tr "/" " ") )
base="/${src[0]}/${src[1]}/${src[2]}"
rardir="${base}/rar"
rarfile="${rardir}/$3.rar"
# This is really BAD advise, but...
files=$(find "$2" -type f -name $3*.bmp)
/opt/rar/rar ${rar_opt} "${rarfile}" "${files}"
I used the command
sh -x compress3.sh password /data/pictures/index/bmp/1999 1999.103 > log.txt
the log.txt has:
RAR 3.11 Copyright (c) 1993-2003 Eugene Roshal 15 Jan 2003
Registered to Joern Steltner
Updating solid archive .rar
Updating c.sh 2% OK
Updating compress.sh 9% OK
Updating compress2.sh 32% OK
Updating c.sh~ 35% OK
Updating compress.sh~ 42% OK
Updating compress2.sh~ 65% OK
Updating compress3.sh 74% OK
Updating compress3.sh~ 97% OK
Updating log.txt 100% OK
Adding data recovery record
Done
The output from sh -x ... I could catch, but for the RAR-command it is:
'' pt/rar/rar a -s -rr1024 -cl -m5 -r0 -hppassword
Kewl. Thnx for the feedback. You're getting somewhere. I take it it works, right?
I'm wondering about the "Updating solid archive .rar" tho, it shows a space where "$3" is supposed to be. If this needs looking into, please catch standard output *and* error output in the same file with "some_command 2>&1 > logfile".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.