PDA

View Full Version : uuencode making me nuts



GofBorg
18-Oct-2012, 23:32
So I've been working on this ksh script to attach a pdf file to an email
using uuencode. Works absolutely brilliant until I put the the script
inside a 'while true do' at which point it wants to attach the pdf as
a zero byte .bin file. WTH? If I remove the while true and just run it
against files in /export/share/pdf all is well. Anyone?

<code>
#!/bin/ksh
while true
do
for name in $(ls /export/share/pdf/ | awk 'BEGIN {FS = "-"} {print $1}')
do
for sendThis in $(ls /export/share/pdf/ | head -n 1)
do
case $name in
"root")
uuencode /export/share/pdf/$sendThis report.pdf | mailx -s
"Report from User1" someone@somewhere.com;;
"steveo")
uuencode /export/share/pdf/$sendThis report.pdf | mailx -s
"Report from User2" someone@somewhere.com;;
esac
rm /export/share/pdf/$sendThis
done
done
done

GofBorg
18-Oct-2012, 23:43
Guess I should mention it works brilliantly as well
run from cron. However I was hoping to have it run as
a background process for snappier response time rather
than polling.

GofBorg
18-Oct-2012, 23:55
I thought perhaps there was a problem with what is getting assigned to
$sendThis. If there is a file in the directory /export/share/pdf when it is
run, the file is sent, and it is correct but each subsequent submission gets
a zero byte file. There are no errors generated and the script keeps
on running. If I put in an echo $sendThis just before the uuencode line
it shows the correct filename.

GofBorg
19-Oct-2012, 00:00
LOL. Think I found the problem.
I had a window open to the directory with KDE Dolphin
which was creating a .directory file when a new file was created which made
head -n 1 incorrect. LOL...oh man. Glad that's over. LOL.

GofBorg
19-Oct-2012, 00:05
> LOL. Think I found the problem.
> I had a window open to the directory with KDE Dolphin
> which was creating a .directory file when a new file was created which
> made
> head -n 1 incorrect. LOL...oh man. Glad that's over. LOL.

Sadly that didn't correct it. :/
Oh well, tired of looking at it today. Pick it up again tomorrow.

Joseph Marton
19-Oct-2012, 00:15
GofBorg wrote:

> Sadly that didn't correct it. :/
> Oh well, tired of looking at it today. Pick it up again tomorrow.

Ever get the feeling you're talking to yourself?

--
Does this washcloth smell like chloroform?

GofBorg
19-Oct-2012, 16:32
> Ever get the feeling you're talking to yourself?
>
Often.

malcolmlewis
19-Oct-2012, 17:16
On Thu, 18 Oct 2012 23:05:08 GMT
GofBorg <GofBorg@no-mx.forums.opensuse.org> wrote:

> > LOL. Think I found the problem.
> > I had a window open to the directory with KDE Dolphin
> > which was creating a .directory file when a new file was created
> > which made
> > head -n 1 incorrect. LOL...oh man. Glad that's over. LOL.
>
> Sadly that didn't correct it. :/
> Oh well, tired of looking at it today. Pick it up again tomorrow.
>
>
Hi
Is there a trigger for the file to be generated that can be polled? You
could use something like SEC (simple event correlater) or perhaps a
udev rule?

--
Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 12.2 (x86_64) Kernel 3.4.11-2.16-desktop
up 15:08, 4 users, load average: 0.07, 0.07, 0.12
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

GofBorg
19-Oct-2012, 18:32
There is something terribly wrong with something.
I have now tried 3 different methods for attaching and sending
the attachment. All of them work until you put them in a simple while
statement. Doesn't matter if I use MUTT, Metasend, uuencod, mmencode.
I get the email with a zero byte attachment. If run outside of a 'while
loop' OR if there is a file already in the directory when the script is
launched, the attachment is normal.

Here is the latest pared down bone simple script. sendThis will echo the
correct filename.

#!/bin/ksh
while true
do
for sendThis in $(ls /export/share/pdf/ | head -n 1)
do
echo $sendThis
metasend -b -t someone@somewhere.com -s "Report for Someone"
-m application/pdf -f /export/share/pdf/$sendThis
rm /export/share/pdf/$sendThis
done
done

GofBorg
19-Oct-2012, 18:40
I think I have it finally working with mutt.

#!/bin/ksh
while true
do
for sendThis in $(ls /export/share/pdf/ | head -n 1)
do
echo $sendThis
echo | mutt -a /export/share/pdf/$sendThis --
someone@somewhere.com
rm /export/share/pdf/$sendThis
done
done

malcolmlewis
19-Oct-2012, 18:42
On Fri, 19 Oct 2012 17:32:32 GMT
GofBorg <GofBorg@no-mx.forums.opensuse.org> wrote:

> There is something terribly wrong with something.
> I have now tried 3 different methods for attaching and sending
> the attachment. All of them work until you put them in a simple while
> statement. Doesn't matter if I use MUTT, Metasend, uuencod, mmencode.
> I get the email with a zero byte attachment. If run outside of a
> 'while loop' OR if there is a file already in the directory when the
> script is launched, the attachment is normal.
>
> Here is the latest pared down bone simple script. sendThis will echo
> the correct filename.
>
> #!/bin/ksh
> while true
> do
> for sendThis in $(ls /export/share/pdf/ | head -n 1)
> do
> echo $sendThis
> metasend -b -t someone@somewhere.com -s "Report for
> Someone" -m application/pdf -f /export/share/pdf/$sendThis
> rm /export/share/pdf/$sendThis
> done
> done
>
Hi
This is what I use in my backup scripts;


/usr/bin/tr -d '\015' < $FILENAME | /usr/bin/mailx -s "$X backup via RSYNC to USB Disk" malcolml@localhost \

Where $FILENAME is what I'm sending.

--
Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 12.2 (x86_64) Kernel 3.4.11-2.16-desktop
up 16:34, 4 users, load average: 0.13, 0.12, 0.08
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

GofBorg
19-Oct-2012, 18:51
Thanks for the assist Malcolm but think I have it
sorted. See above post. You missed the excitement this
morning though when I flooded my mailbox with 3,200 messages...yah, got
my loop a bit wrong when I left out the rm statement. :)