1837531 Members
3427 Online
110117 Solutions
New Discussion

Script help

 
SOLVED
Go to solution
Anthony khan
Frequent Advisor

Script help

Hi Guys, I have written the following script to check in directory for the files and email the user that files arrive with the files name and mv the files to different directory, Now what I want is to attach the same file with the email, Can someone help me out, here's the script.......

#!/usr/bin/sh
DIR2SRCH="/playpen/td"
FILE2FIND="td*.txt"
EXCLUDEDIRS='-e \/old\/ -e \/data\/'
file=" "
filecheck=" "
filecheck=`find ${DIR2SRCH} -type f -name "${FILE2FIND}" -size +0c -exec ls -l {} \; |grep -v ${EXCLUDEDIRS} |cut -c71-90`
if [ -z "$filecheck" ]
then
exit
else
find ${DIR2SRCH} -type f -name "${FILE2FIND}" -size +0c -exec ls -l {} \; |grep -v ${EXCLUDEDIRS} |cut -c71-90|mailx -s "Files arrive" email address
for file in `find ${DIR2SRCH} -type f -name "${FILE2FIND}" -size +0c -exec ls -l {} \; |grep -v ${EXCLUDEDIRS} |cut -c71-90`
do
mv /playpen/td/$file /playpen/td/data/$file
done
fi
17 REPLIES 17
Justo Exposito
Esteemed Contributor
Solution

Re: Script help

Hi,

Try to use uuencode to send the mail, there are more information in man pages.

Regards,

Justo.
Help is a Beatiful word
Justo Exposito
Esteemed Contributor

Re: Script help

Hi Anthony

This is from the man page:
To encode and send a compiled program foo to user friend:

uuencode foo foo | mailx -s 'new program' friend

After receiving the mail message, user friend can decode the program
by first saving the message in a file foo.mail and executing the
command:

uudecode foo.mail

Hope this help,

Justo.
Help is a Beatiful word
Jeff Schussele
Honored Contributor

Re: Script help

Hi Anthony,

Would add something like

uuencode $FILE2FIND | mailx -s "subject_line" user@domain.com

OR

mailx -s "subject_line" user@domain.com < uuencode $FILE2FIND

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Hai Nguyen_1
Honored Contributor

Re: Script help

This code should work as well.

(
echo "From: "
echo "To: "
echo "Subject: "
echo "This is the body of the e-mail.
If you are having any problem with this file please give us a call.


"
/usr/bin/uuencode /local/filename filename
) | /usr/sbin/sendmail user@company.com

Hai

Anthony khan
Frequent Advisor

Re: Script help

Hi,

uuencode $filecheck | mailx -s "subject_line" user@domain.com

I am getting this in email

begin 0 tdmgw.ret.txt
.=&1M9W`
end

The email will go to window or NT system, Can someone put the light here
Justo Exposito
Esteemed Contributor

Re: Script help

Hi Anthony,

This is because you must put:
uuencode $filecheck $filecheck| mailx -s "subject_line" user@domain.com

Regards,

Justo.
Help is a Beatiful word
Jeff Schussele
Honored Contributor

Re: Script help

Anthony,

Yep Justo is correct.
Sorry I left out the output filename in the uuencode command.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Justo Exposito
Esteemed Contributor

Re: Script help

Hi Again,

I forgot to tell you that perhaps you need to change the file format from HP/UX to DOS format, to do this you need the command ux2dos
see the man page.

Regards,

Justo.
Help is a Beatiful word
Anthony khan
Frequent Advisor

Re: Script help

Hi Justo,

After doing uuencode $filecheck $filecheck |mailx -s "files arrive" email, i am getting this now

begin 644 tdmgw.ret.txt
M8V%T('-P:&EN>"YP87-S=V0@?'-OM;W0@?&-U="`M9"(Z(B`M9C,L-2!\('-E="`G<>W!R:6YT9B@B)35D)7-<;B(L)#$L)#(I?2<@"B\L
`
end
S.K. Chan
Honored Contributor

Re: Script help

Check out Rita's method (the 2nd last reply) in this thread. It appends the "include" statement to the file before sending it out.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x859903bbece8d5118ff40090279cd0f9,00.html

Justo Exposito
Esteemed Contributor

Re: Script help

Hi Anthony,

Can you try to do with a simple ascii file?
I just tried with a simple ascii file called probe and it work fine between my HP/UX and my NT with outlook.

uuencode probe probe |mailx -s 'hello' myuser@mydomain.es

If you try it and all it's good then you can put the right sentence in your complex script.

Regards,

Justo.
Help is a Beatiful word
SHABU KHAN
Trusted Contributor

Re: Script help

Hi Anthony,

You need a -m flag for mailx to send it as an attachment ...
check the man pages for mailx


uuencode filename filename | mailx -m -s "subject" abc@abc.com


Thanks,
Shabu
benoit Bruckert
Honored Contributor

Re: Script help

Hi,
On my side, I'm using another tool called 'nail' which create mime attachment.
You can download it at
http://hpux.cs.utah.edu/hppd/hpux/Networking/Mail/nail-9.30/

syntax is quite the same as mail and is very easy to use.
Une application mal pansée aboutit à une usine à gaze (GHG)
Justo Exposito
Esteemed Contributor

Re: Script help

Hi Anthony,

This works?
This is closed?

Regards,

Justo.
Help is a Beatiful word
Anthony khan
Frequent Advisor

Re: Script help

Hi Justo, Sorry I was busy on other stuff, I am able to attach 1 file with the following command but unable to attach multiple files, can someone help,

ux2dos $filecheck > convertfile
uuencode convertfile convertfile|mailx -m -s "files arrive" emailadd.

Can someone help how to attach multiples files
Anthony khan
Frequent Advisor

Re: Script help

My script now is...

#!/usr/bin/sh
DIR2SRCH="/playpen/td"
FILE2FIND="td*.txt"
EXCLUDEDIRS='-e \/old\/ -e \/data\/'
file=" "
filecheck=" "
filecheck=`find ${DIR2SRCH} -type f -name "${FILE2FIND}" -size +0c -exec ls -l {} \; |grep -v
${EXCLUDEDIRS} |cut -c71-90`
if [ -z "$filecheck" ]
then
exit
us2doc $filecheck > convertfile else
find ${DIR2SRCH} -type f -name "${FILE2FIND}" -size +0c -exec ls -l {} \; |grep -v
${EXCLUDEDIRS} |cut -c71-90|uuencode convertfile convertfile|mailx -m -s "Files arrive" email address
for file in `find ${DIR2SRCH} -type f -name "${FILE2FIND}" -size +0c -exec ls -l {} \; |grep -v
${EXCLUDEDIRS} |cut -c71-90`
do
mv /playpen/td/$file /playpen/td/data/$file
done
fi
Justo Exposito
Esteemed Contributor

Re: Script help

Hi Anthony,

I think that you must zip your files in one and then use uuencode, there are a free pkzip software for HP/UX in this page:

http://hpux.connect.org.uk/hppd/hpux/

Best Regards,

Justo.
Help is a Beatiful word