Automated e-mailer problem

I am trying to write a bash e-mailer script on a host that has a bunch of CPUs and makes use of all of them. It e-mails a huge list of people, so I wanna save time running this script if I can.

for uid in `echo $members`
do
(
...
/usr/sbin/sendmail -t < $tmp
...
) &
done

wait

What e-mails it does send get sent concurrently, but most don't get sent at all.

There is a serial version of this script that definitely sends out more e-mails.

I'm wondering if those running sendmail are blocking others from running sendmail on the same CPU?

Is there anything I can do? Thanks

That is a useless use of backticks, you could have simply written for uid in $members

Is there any particular reason they need to be sent simultaneously? All it ought to be doing is putting them in the queue, so there wouldn't be an enormous delay from running it one-at-a-time.

assuming that sendmail -t $tmp does work to send email. I do not see where the $uid variable gets used to address email. Oh well.
bash or ksh example using your code fragment:

#!/bin/bash
cnt=0;
for uid in $members
do
   sendmail -t  < $tmp
   cnt=$(( $cnt + 1 ))
   [  $(( $cnt % 15 )) -eq 0 ]   && wait
done 
wait

This sends 15 at one pass. You may have exceeded resource limits trying to send hundreds of emails at one time. I agree with corona -sometimes we have requirements that are there for a really poor reasons. Why is there a major time constraint on this job? Or are you simply learning how to do this?

1 Like

What I put is not actual code, I just wrote that to give you guys an idea of what I'm trying to do. The code I did show was not copied verbatim. I apologize for the confusion.

I will give Jim's code a try.

---------- Post updated at 08:59 PM ---------- Previous update was at 08:20 PM ----------

I found out how to get the # of CPU. I guess if one of the CPUs happen to be too busy, then an e-mail may not get sent?

---------- Post updated at 09:04 PM ---------- Previous update was at 08:59 PM ----------

Was able to reduce the runtime from 30min to 6min, looks like all e-mails got sent. It checks to see how many CPUs the host has then tries to do a sendmail on each of them I imagine.

No. That has nothing to do with it. Any UNIX system can multitask.

It has more to do with how much RAM your user is allowed to use, or how many simultaneous processes you're allowed to create, than how many CPU's you have. Having your script limit itself in any fashion would and did help.

Your script is probably slow for reasons other than sendmail. If you're new to shell, there may be some simple things turned inside out. Post it and we can help.

I'm not sure I remember things correctly, but what about creating "mailing lists" with sth. like a dummy address in aliases and send all the mails in one go?