# uuencode making me nuts

**URL:** <https://forums.suse.com/t/uuencode-making-me-nuts/23217>\
**Category:** Chatting over the Back Fence\
**Created:** [October 19, 2012, 1:32am UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217 "2012-10-19T01:32:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![System1](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@System1](https://forums.suse.com/u/System1)\
**Post date:** [October 19, 2012, 1:32am UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217/1 "2012-10-19T01:32:30Z")

</div>

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?

`  
#!/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](mailto:someone@somewhere.com);;  
“steveo”)  
uuencode /export/share/pdf/$sendThis report.pdf | mailx -s  
“Report from User2” [someone@somewhere.com](mailto:someone@somewhere.com);;  
esac  
rm /export/share/pdf/$sendThis  
done  
done  
done

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [October 19, 2012, 1:43am UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217/2 "2012-10-19T01:43:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [October 19, 2012, 1:55am UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217/3 "2012-10-19T01:55:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [October 19, 2012, 2:00am UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217/4 "2012-10-19T02:00:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [October 19, 2012, 2:05am UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217/5 "2012-10-19T02:05:08Z")

</div>

> LOL. Think I found the problem.[color=blue]  
> 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.[/color]

Sadly that didn’t correct it. 😕  
Oh well, tired of looking at it today. Pick it up again tomorrow.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [October 19, 2012, 2:15am UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217/6 "2012-10-19T02:15:44Z")

</div>

GofBorg wrote:  
[color=blue]

> Sadly that didn’t correct it. 😕  
> Oh well, tired of looking at it today. Pick it up again tomorrow.[/color]

Ever get the feeling you’re talking to yourself?

–  
Does this washcloth smell like chloroform?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [October 19, 2012, 6:32pm UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217/7 "2012-10-19T18:32:44Z")

</div>

> Ever get the feeling you’re talking to yourself?[color=blue]  
> [/color]  
> Often.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [October 19, 2012, 7:16pm UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217/8 "2012-10-19T19:16:14Z")

</div>

On Thu, 18 Oct 2012 23:05:08 GMT  
GofBorg [GofBorg@no-mx.forums.opensuse.org](mailto:GofBorg@no-mx.forums.opensuse.org) wrote:  
[color=blue][color=green]

> > 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.[/color]
> 
> Sadly that didn’t correct it. 😕  
> Oh well, tired of looking at it today. Pick it up again tomorrow.
> 
> [/color]  
> 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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [October 19, 2012, 8:32pm UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217/9 "2012-10-19T20:32:32Z")

</div>

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](mailto:someone@somewhere.com) -s “Report for Someone”  
-m application/pdf -f /export/share/pdf/$sendThis  
rm /export/share/pdf/$sendThis  
done  
done

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [October 19, 2012, 8:40pm UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217/10 "2012-10-19T20:40:12Z")

</div>

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](mailto:someone@somewhere.com)  
rm /export/share/pdf/$sendThis  
done  
done

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [October 19, 2012, 8:42pm UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217/11 "2012-10-19T20:42:56Z")

</div>

On Fri, 19 Oct 2012 17:32:32 GMT  
GofBorg [GofBorg@no-mx.forums.opensuse.org](mailto:GofBorg@no-mx.forums.opensuse.org) wrote:  
[color=blue]

> 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](mailto:someone@somewhere.com) -s “Report for  
> Someone” -m application/pdf -f /export/share/pdf/$sendThis  
> rm /export/share/pdf/$sendThis  
> done  
> done  
> [/color]  
> Hi  
> This is what I use in my backup scripts;

```auto
/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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [October 19, 2012, 8:51pm UTC](https://forums.suse.com/t/uuencode-making-me-nuts/23217/12 "2012-10-19T20:51:36Z")

</div>

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. 🙂
