Help me While zipping the file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Help me While zipping the file
# 1  
Old 05-09-2007
Question Help me While zipping the file

Hi ,

I have written code which will ask the subject,body of the mail, attachment and mail id of the receipient.
Code will pick up 4 files zip it. It will zip all the files and then post the mail to the receipient. While zipping the file i am getting error. Can anyone help me with this.

#!/bin/Sh

##Parameters to be passed
echo 'What subject do you want to put for mail'
read subject

echo 'Pass the path of the text file containing the body of the mail'
read body

echo 'Pass the path of the files need to be attached'
read attachment_path

echo 'Pass the mail id'
read mail_receiver


##Start of Program
cd $attachment_path
echo 'current path is' `pwd`


## Count and initialize parameters
count=`ls|wc -l`
echo 'count is '$count
a=0


##introduced while loop to pick up the first 4 files and zip. Delete the files that are already zipped and pick the other file
## to be zipped

while [ $count -gt 0 ]
do
ls|head -4 > zipfiles
cat zipfiles
sed - e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/AbcdeFghIjklmnopqRstuvwxyz/' -e "s/^/\'/" -e "s/$/\'/" <zipfiles> zfile

list_of_file=`cat zfile`
echo $list_of_file

a=`expr $a + 1`
zip Snaps[$a] $list_of_file
rm $list_of_file
count=0
echo 'Files zipped'
rm zfile
done

## This block send the mail to the receiver.
file=`ls`
echo 'count of zip file -' $file
for i in $file
do
echo $i
var=$i
( cat $body
uuencode $var $var
) | mailx -s "$subject" ${mail_receiver}

done
***************************------**********************

While Executing this I am getting error :

current path is /export/home/jmirani/MAILExample/attach
count is 120
First month of RIA 001.jpg
First month of RIA 002.jpg
First month of RIA 003.jpg
First month of RIA 004.jpg
'First month of RIA 001.jpg' 'First month of RIA 002.jpg' 'First month of RIA 003.jpg' 'First month of RIA 004.jpg'
mail.sh[57]: 'First: not found

zip error: Nothing to do! (Snaps[1].zip)
'First: No such file or directory
month: No such file or directory
of: No such file or directory
RIA: No such file or directory
001.jpg': No such file or directory
'First: No such file or directory
month: No such file or directory
of: No such file or directory
RIA: No such file or directory
002.jpg': No such file or directory
'First: No such file or directory
month: No such file or directory
of: No such file or directory
RIA: No such file or directory
003.jpg': No such file or directory
'First: No such file or directory
month: No such file or directory
of: No such file or directory
RIA: No such file or directory
004.jpg': No such file or directory
Files zipped


All though files have been put into string still zip takes the wrong file name. Any help with this is much appreciated.

I tried zip trial 'First month of RIA 001.jpg' 'First month of RIA 002.jpg' 'First month of RIA 003.jpg' 'First month of RIA 004.jpg'
and this works properly.But code doesn't work?
# 2  
Old 05-09-2007
It is very hard to to work with filenames that contain embedded blanks. The files are broken up by the spaces. You will need to arrange for each file name to be surrounded by quotes.
# 3  
Old 05-10-2007
I have already arrange the files surrounded by quote, but for some reason it is giving error while zipping the files. I have also provided the results with the problem occuring.
# 4  
Old 05-10-2007
I treied your script. I don't know how it got it run like that. I had to fix the sed statement. You have:
sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/AbcdeFghIjklmnopqRstuvwxyz/' -e "s/^/\'/" -e "s/$/\'/"
that first "- e" should not have a space between the - and the e. I didn't have zip, so I chaged it to "ls -l" for testing. At first I got the same errors as you. But then this worked:
eval ls -l $list_of_file
# 5  
Old 05-10-2007
space in sed was my copy paste mistake.

I am also doinf echo before zipping and i am getting :
'First month of RIA 001.jpg' 'First month of RIA 002.jpg' 'First month of RIA 003.jpg' 'First month of RIA 004.jpg'

Every file is surrounded by quotes and should be picked up correctly while zipping but not getting picked.

Can someone help mw with why zip command is not picking up the files peoperly.

I tried this maually

zip <ZIPFILENAME> 'First month of RIA 001.jpg' 'First month of RIA 002.jpg' 'First month of RIA 003.jpg' 'First month of RIA 004.jpg'

above commna dworked properly and created <ZIPFILENAME>.zip

Help HelpHelp!!!!!!!!
# 6  
Old 05-10-2007
If you won't try "eval" there is no point in trying to help you.
# 7  
Old 05-10-2007
I am more than happy to try eval, unfortunately don't know what and where should i put this to get the result i am expecting.

I have read the help of eval command, but since eval doesn't zip the file , i haven't tried it.

Can you put the command in the appropriate place of the script i have pasted, and i will be more than happy to try this.

Sorry for any inconvenience caused.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Zipping file issues

Hi All, I am trying to zip a file but facing the issue. I have three zip files. a_1.zip a_2.zip c.zip I want to add a_1.zip and a_2.zip to c.zip Code: ############### for i in a*.zip; do printf "%s\n" "$i" done | zip -@ c.zip (2 Replies)
Discussion started by: weknowd
2 Replies

2. Shell Programming and Scripting

Error in Zipping a file

Hi I am trying to create a zip file of a csv by running below script. zip -r Daily_DB_`date '+:%d/%m/%y'` DBA_checks.csv But I am getting below error zip I/O error: No such file or directory zip error: Could not create output file (Daily_DB_:02/11/12.zip) However when I run below... (1 Reply)
Discussion started by: sv0081493
1 Replies

3. UNIX for Dummies Questions & Answers

Help With zipping a file

Hi I need to zip a file and move it into another folder along with the timestamp. The orginal file must be removed from the source directory Source : folder1/source12.txt folder2 After zipping Folder1/Folder2/source12.zip Any help will be greatly appreciarted ... (5 Replies)
Discussion started by: akshay01987
5 Replies

4. UNIX for Dummies Questions & Answers

Zipping the file when moving

Hi, I have a file a.txt, I am moving the file from my source location (/root/onw/src) to target folder(root/byl/src). My target folder has already a file by name a.txt..,while moving can I see if this file a.txt is existing then move it to archive folder(/root/byl/arc) zip and add time stamp to... (2 Replies)
Discussion started by: shruthidwh
2 Replies

5. Shell Programming and Scripting

grep a file and zipping it

Hi, In my process iam creating a temporary filelist with filename and date(yyyy-mm-dd format).I need to search file for a date and zip. Below command is giving the filename ,can someone helpme how to add the zip or gzip command to this statement. grep 2010-11-11 filelist.log | awk... (1 Reply)
Discussion started by: swathich
1 Replies

6. Shell Programming and Scripting

Zipping of file in a different directory

Hi, I am having some problem with a shell script which zip some files. For zipping I have used the following command: find . -name "Test_*" -mtime 0 | zip Test_$(date +"%Y%m%d") -@ I have kept the script in /home/abc directory. It is creating the zip file within the same directory where i... (2 Replies)
Discussion started by: abhishek_510
2 Replies

7. Shell Programming and Scripting

zipping a directory when the file count is over $X

Hiya, I've been plugging away at this script and I cant get it to behave as I need. first off it fails to adhere to the conditions of the file limit, and zips the directory regardless of the file count and secondly, but less important it zips up the entire path not just the directory I'm... (2 Replies)
Discussion started by: orionrush
2 Replies

8. UNIX for Dummies Questions & Answers

zipping all the tar files to singlr file in directory

Hi, i have more than 300 tar files in directory and i want to zip all tar files to single file. could anybody tell me the command since i know how to do zip for single tar file: bash-3.00$gzip 2008_11_10.tar bash-3.00$ pwd /oracle1/archivebackup in this directory i have lot files... (2 Replies)
Discussion started by: prakash.gr
2 Replies

9. Shell Programming and Scripting

Script for zipping a file

HI, I want a script which creat a zip file folder of files older than 15 days....... please help me on this........... (4 Replies)
Discussion started by: jayaramanit
4 Replies

10. AIX

Limitations of a file size for zipping

what is the maximum file size that i can zip in aix. (1 Reply)
Discussion started by: ramky79
1 Replies
Login or Register to Ask a Question