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;;
“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
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.
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.
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.
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.
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
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
#!/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
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
[/color]
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
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.