Operating System - HP-UX
1834926 Members
2559 Online
110071 Solutions
New Discussion

Help needed for Small Script.

 
SOLVED
Go to solution
Mark Blonde
Advisor

Help needed for Small Script.

Hello all,
I was wondering if you can help me with my little script. The purpose of the script is to send me an email with every text file that contains more than 1 line as a seperate attachement. Here is my code.

**************************************
#/bin/sh
ls *.txt | while read FILE
do
NL=`wc -l $FILE | awk '{print $1}'`
if [ $NL -gt 1 ]; then
ls $FILE | awk '{ system ("ux2dos " $1 " | uuencode " $1 " | /usr/lib/sendmail " )}'
fi
done
***************************************************

The problem with that script, is that it sends an email per file. (of course).
I was wondering if you can tell me a way to send 1 email with all txt files as seperate attachements sent.

Thanks
If you don't have what you want, want what you have.
3 REPLIES 3
Rodney Hills
Honored Contributor

Re: Help needed for Small Script.

First create a file with the following line-

[include test1.txt application/text base64]
[include test2.txt application/text base64]

Second from the command line:
elm -s "your subject" user@yoursite.com

Where "file" contains the necessary [include] lines.

-- Rod Hills
There be dragons...
Mark Blonde
Advisor

Re: Help needed for Small Script.

The suggestion you have works fine. The only problem is that I don't exactly know how to fix the command ux2dos and/or uuencode so that the txt files sent through email are readable. can you help ?
If you don't have what you want, want what you have.
Rodney Hills
Honored Contributor
Solution

Re: Help needed for Small Script.

You shouldn't have to worry about using encode on the text (the base64 takes care of that).

The ux2dos will need to be run. So just copy each file to /tmp and email the converted files.

Here is your script updated-
#/bin/sh
cat /tmp/listfiles
ls *.txt | while read FILE
do
NL=`wc -l $FILE | awk '{print $1}'`
if [ $NL -gt 1 ]; then
ux2dos <$FILE >/tmp/${FILE}crlf
echo "[include /tmp/${FILE}crlf application/text base64]" >>/tmp/listfiles
fi
done
elm -s "Here are your files" user@yoursite.com rm /tmp/listfiles
rm /tmp/*crlj

-- Rod Hills
There be dragons...