LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 05-17-2003, 03:37 PM   #1
steltner
LQ Newbie
 
Registered: May 2003
Posts: 18

Rep: Reputation: 0
shell script problem


Hallo together,

I had an idea and I got a problem:

script 1 (compress.sh):
-----------------------------
#! /bin/sh
/opt/rar/rar_static $3 -s -rr8 -cl -hp$4 -m5 ../index/rar/$1/$1.$2.01.rar ../index/bmp/$1/$1.$2*.bmp

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

May someone give me an advice.

Joern
joern@steltner.com
 
Old 05-17-2003, 03:58 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
Is that the definate path?
What is you dir structure like?
Where were you when you ran that command?
Have you tried using the full path?

PS Prepare for a flaming from the mods for double posting
 
Old 05-17-2003, 04:09 PM   #3
steltner
LQ Newbie
 
Registered: May 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Hallo David,

1) \data\pictures\index\bmp\1999
\rar\1999
2)the structure like at 1)
3) \data\pictures\_batches
4) jepp, I tried with full path, same result

Joern
 
Old 05-17-2003, 04:14 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
What happens if you do:
ls -l ../index/bmp/1999/1999.103*.bmp

from the _batches directory? Do you see the files?
 
Old 05-17-2003, 04:15 PM   #5
steltner
LQ Newbie
 
Registered: May 2003
Posts: 18

Original Poster
Rep: Reputation: 0
ls -l ../index/bmp/1999/1999.103*.bmp

shows me all the file I want add to the archive ;-)
 
Old 05-17-2003, 04:28 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
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.
 
Old 05-17-2003, 04:32 PM   #7
steltner
LQ Newbie
 
Registered: May 2003
Posts: 18

Original Poster
Rep: Reputation: 0
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 ;-)
 
Old 05-17-2003, 04:38 PM   #8
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
Have you tried using -c instead of -x:
sh -c compress.sh 1999 103 a password
 
Old 05-17-2003, 04:39 PM   #9
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
Sorry - it should have had quotes too:
sh -c "compress.sh 1999 103 a password"
 
Old 05-17-2003, 05:10 PM   #10
steltner
LQ Newbie
 
Registered: May 2003
Posts: 18

Original Poster
Rep: Reputation: 0
sh -c compress.sh 1999 103 a password
sh -c "compress.sh 1999 103 a password"

doesn't work!

sh -x compress.sh 1999 103 a password

works, but with the problem described on top
 
Old 05-17-2003, 09:17 PM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594
warning, lame code ahead...

Code:
#!/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).
 
Old 05-18-2003, 05:02 AM   #12
steltner
LQ Newbie
 
Registered: May 2003
Posts: 18

Original Poster
Rep: Reputation: 0
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.
 
Old 05-18-2003, 05:45 AM   #13
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594
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? :-]
 
Old 05-18-2003, 06:55 AM   #14
steltner
LQ Newbie
 
Registered: May 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Dear moderator,

first of all many thanks for your advices!!

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
 
Old 05-18-2003, 07:29 AM   #15
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594Reputation: 3594
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".
 
  


Reply


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
A problem about a shell script jpan Linux - General 2 01-19-2005 06:14 PM
Problem in shell script Kumar Programming 4 04-27-2004 08:48 AM
Shell-Script Problem? x4v013 Slackware 7 09-17-2003 12:15 AM
shell script problem steltner Programming 0 05-17-2003 03:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:23 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