The UNIX Forums
"Join the Network of UNIX System Users"


 
Subject: help me while zipping the file
-jay-
Newbie
Rank: 1



UID 26
Digest Posts 0
Credits 0
Posts 47
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:21 AM  Profile | P.M. 
help me while zipping the file



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?


Top
DemonMaster
Newbie
Rank: 1



UID 114
Digest Posts 0
Credits 0
Posts 55
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:22 AM  Profile | P.M. 
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.
Top
MD.45
Newbie
Rank: 1



UID 259
Digest Posts 0
Credits 0
Posts 25
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:22 AM  Profile | P.M. 
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.
Top
Mantisby
Newbie
Rank: 1



UID 249
Digest Posts 0
Credits 0
Posts 27
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:22 AM  Profile | P.M. 
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:
Top
gydqw
Newbie
Rank: 1



UID 169
Digest Posts 0
Credits 0
Posts 29
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:22 AM  Profile | P.M. 
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
Top
CountryBoy
Newbie
Rank: 1



UID 98
Digest Posts 0
Credits 0
Posts 27
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:22 AM  Profile | P.M. 
if you won't try "eval" there is no point in trying to help you.
Top
ajscottsr
Newbie
Rank: 1



UID 44
Digest Posts 0
Credits 0
Posts 51
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:22 AM  Profile | P.M. 
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.
Top
Eightrix
Newbie
Rank: 1



UID 132
Digest Posts 0
Credits 0
Posts 45
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:22 AM  Profile | P.M. 
tried changing the name of the file, still zip is giving the error. refer out put below.

current path is /export/home/jmirani/mailexample/attach
count is 122
a001.jpg
a002.jpg
a003.jpg
a004.jpg
'a001.jpg' 'a002.jpg' 'a003.jpg' 'a004.jpg'
zip warning: name not matched: 'a001.jpg'
zip warning: name not matched: 'a002.jpg'
zip warning: name not matched: 'a003.jpg'
zip warning: name not matched: 'a004.jpg'

zip error: nothing to do! (snaps[1].zip)
'a001.jpg': no such file or directory
'a002.jpg': no such file or directory
'a003.jpg': no such file or directory
'a004.jpg': no such file or directory
Top
 

 

All times are GMT, the time now is Mar 21, 2010 12:08 AM

Powered by Discuz! 5.0.0  © 2001-2006 UNIX Forums
Processed in 0.230219 second(s), 8 queries

Clear Cookies - Contact Us - UNIX Help - Archiver - WAP