Unzipping the empty file sends a non Zero return code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unzipping the empty file sends a non Zero return code
# 1  
Old 01-16-2014
Unzipping the empty file sends a non Zero return code

Hi,

I have a shell script where I am trying to unzip bunch of files zip files one by one. But out of many zip files, if any one zip file is empty, the unzip command sends a non-zero return code and fails the script.

I am trying to see if I can get a success error code even if the script tries to unzip an empty zip file.

Code:
sample code snipet
 
cd  DIR1
for zipfilename in `cat /DIR2/$zipfilename.txt`
do
cp zipfilename /tmp/.
unzip -n zipfilename 
rc=$?
 
if $rc != 0 then 
echo "Process fail"
fi


Last edited by Saanvi1; 01-16-2014 at 01:20 AM..
# 2  
Old 01-16-2014
Hello,

Following is the example for checking the zero and non-zero size zip files.

Code:
$ cat check_gz.ksh
find . -name "*.gz" | sed 's/\.\///g' > /tmp/checkcheck1211
while read line
do
if [[ -s $line ]]
then
echo $line "File is non-zero size"
else
echo $line "File is zero size"
fi
 
done < "/tmp/checkcheck1211"


In place of echo we can put the appropriate commands or conditions as per your requirement please.


Thanks,
R. Singh
# 3  
Old 01-16-2014
Are you trying to unzip a zero byte file? That is not a zipped file. A zero byte file that has been zipped has a size:-
Code:
$ touch robin
$ zip -r robin robin
  adding: robin (stored 0%)
$ ls -l
total 4
-rw-r--r-- 1 batterra techsupp   0 Jan 16 13:45 robin
-rw-r--r-- 1 batterra techsupp 160 Jan 16 13:45 robin.zip
$ unzip -p robin    
[robin]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
$ unzip -p robin.zip
$

There is no output from the final command because the original file is empty.



I hope that this helps,
Robin
Liverpool/Blackburn
UK
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass back return code for file delete failure

Hello Experts, This script to delete a file is submitted from an SAP system which has 2 servers. When it happens to run on server 1, the delete is successful. When it runs on server 2, the delete always fails. All user accounts and permissions have been adjusted to match on both servers. Is it... (5 Replies)
Discussion started by: SAPDEVEL
5 Replies

2. Shell Programming and Scripting

Unzipping .Z file in UNIX

Hi , How can I unzip a .Z file in Unix? Thanks and regards, Anupam (3 Replies)
Discussion started by: Anupam_Halder
3 Replies

3. Shell Programming and Scripting

Unzipping the file

I have my folder structure like a file a.zip is placed in one folder. Inside a.zip is two other zip files x.zip and y.zip If i unzip x.zip i have folder a folder z and inside folder z there are different folders with event time appended to it. Inside the every event folder ,I have a sub folder... (1 Reply)
Discussion started by: weknowd
1 Replies

4. Shell Programming and Scripting

Script to Alert a file and sends an email

Hello All, I need a script which alerts me when a files arrive in a directory. I don't need every file. but i need some specific pattern file. And i need to get automatic email gettin as an alert For Example: /a/b/c/ : directory format of file should take regualr expression or manually... (2 Replies)
Discussion started by: krux_rap
2 Replies

5. Linux

unzipping file > 2gb

I am not able to unzip file greater then 2gb, Any suggestions how to do that in linux? Regards, Manoj (5 Replies)
Discussion started by: manoj.solaris
5 Replies

6. Shell Programming and Scripting

Grep to return a code from accessing variable file name

All I want to do is find out if the string 'NO' is in a file by checking for a return code of 0 if there is a match. The grep works fine on the command line directly naming the file but I am obviously not using the correct syntax within the shell script as I consistently get the error message ... (5 Replies)
Discussion started by: SusanDAC
5 Replies

7. UNIX for Dummies Questions & Answers

Getting same exit status for empty and non empty file

Hi All, I am checking for a empty input file to do some further action , but I am getting exit status 0 in both the cases , for empty and non empty file both. The value of $? is coming 0 in if part also and else part too. #!/bin/ksh if ]; then echo "data" # exit 0 echo "$?" else... (4 Replies)
Discussion started by: mavesum
4 Replies

8. UNIX for Dummies Questions & Answers

to check if file is empty or not and return a non zero value

Hi All, I am new to unix worldd . I need to check a file1 if its empty or not. If its empty then return a non zero value say 99 could you pls let me know the perl script for this. (2 Replies)
Discussion started by: mavesum
2 Replies

9. Shell Programming and Scripting

write the script to get the file size and sends an email

hi all Anybody have an idea to write the script to get the file size and sends an email when file size increse more than 10mb. thanks (10 Replies)
Discussion started by: s_linux
10 Replies

10. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies
Login or Register to Ask a Question