catch unzip errors


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers catch unzip errors
# 1  
Old 09-04-2008
catch unzip errors

Hi everybody,
I'm new to linux world and I need your help!!

I'm using vi to create a .sh script that process files moving them from a directory to another and unzipping a file.
I need to catch errors while moving or unzipping files.

For move command, I do:

mv -f $fromdir/${file_dir}$extdati $todir
rcmv=$?
if ((rcmv!=0))
then
RC=2

How can I catch unzip error like for mv? Is there something like rcmv?
I do:

unzip $prefzip$mercato.$extdati -d $todir

Thanks
Laetitia
# 2  
Old 09-04-2008
Any competently written Unix command will set its return code $? to zero for success, non-zero for error. The magic is not in "rcmv" but in "$?"

The idiomatic way to write that is to simply use "if mv". The if conditional examines the result code $? from the command it invokes, and takes the then branch if it's zero, otherwise the else branch (if present).

Code:
if mv -f "$fromdir/${file_dir}$extdati" "$todir"; then
  RC=2
fi
if ! unzip "$prefzip$mercato.$extdati" -d "$todir"; then
  echo error
fi

# 3  
Old 09-04-2008
Sorry, I'm blond!! Smilie

Thanks for make me feel stupid, is the only way to learn!
I'll improve my linux-knowhow...

Bye
Laetitia
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to catch errors in a shell script ( multiple commands )?

Hi I have a shell script like that Main() { DAY=$(date +"%d-%m-%Y") TIME=$(date +"%T") Command 1 Command 2 ... Command n } I would like to catch errors from all commands in Main() and write these errors into a file , something likes this: Main if < error > then echo... (3 Replies)
Discussion started by: bobochacha29
3 Replies

2. Shell Programming and Scripting

Unzip the .zip file without using unzip utility in UNIX

I have .zip file, i want to list all the files archived in the zip file. unzip utility is not working for me in unix. Please help me resolve this issue Thanks ganesh. (3 Replies)
Discussion started by: Ganesh L
3 Replies

3. Programming

help with C try catch

can someone give me an example of try catch in C, everytime i do it under the main, i get some try undeclared error, and dont know how to fix it... (3 Replies)
Discussion started by: omega666
3 Replies

4. Shell Programming and Scripting

How to Unzip a file using unzip utility for files zipped without zip utility ?

Hi, I need to zip/compress a data file and send to a vendor. The vendor does have only unzip utility and can accept only .ZIP files. I do not have zip utility in my server. How do I zip/compress the file so that it can be deflated using unzip command ? I tried gzip & compress commands, but... (1 Reply)
Discussion started by: Sabari Nath S
1 Replies

5. Shell Programming and Scripting

Not able to catch psftp errors

Hi, While running the psftp with the below code,it is able to connect and open the ftp connection and closed the connection. But my scriptfile Test.ftp,is having the code "cd directoryname" where the directoryname does not exists. In this case i should be able to catch the error,instead it is... (1 Reply)
Discussion started by: nsrihari
1 Replies

6. Shell Programming and Scripting

How to Unzip a .ZIP file in Unix without using unzip cmd..?????

Hi All I have ftped a .ZIP file (zipped using WinZip in Windows) to my Unix server (HP-UX). I don't have unzip cmd available in my curent Unix version Please let me know any cmd in UNIX (other than unzip) using which I can unzip this .ZIP file . Please elaborate on the commands aval and... (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

7. Linux

Help req for...shell script to catch "db2 connect" errors ...

Hello friends, Assume that, I am trying to execute a "db2 connect" command from Linux shell prompt via a shell script called "sample" sample db2 connect to bas39 $sample If the database is not present its should display a custom error message by catching the error message given by db2.... (1 Reply)
Discussion started by: frozensmilz
1 Replies

8. HP-UX

How to Unzip a .ZIP file in Unix without using unzip cmd..?????

Hi All I have ftped a .ZIP file (zipped using WinZip in Windows) to my Unix server (HP-UX). I don't have unzip cmd available in my curent Unix version Please let me know any cmd in UNIX (other than unzip) using which I can unzip this .ZIP file . Please elaborate on the commands aval and... (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

9. Shell Programming and Scripting

how to detect errors in unzip

Hello I am trying to write a script that internally will invoke unzip on some .zip file I would like to make my script robust by checking for any possible error that might occur during the unzipping. Are there any arguments that I can add to the unzip command which will let me know if an... (2 Replies)
Discussion started by: jasongr
2 Replies

10. UNIX for Dummies Questions & Answers

How to catch the rscyn errors?

Hi, In my code, I am running rsync, if any error comes, I have to wirte the error to temp file and I want to send this temp file content to specified email address, I am getting starnge outpout, can you pls help to solve this? My code is: tempfile=error.`date '+%m%d%Y_%H%M%SGMT'` rsync -az -e... (3 Replies)
Discussion started by: redlotus72
3 Replies
Login or Register to Ask a Question