Sendmail from cron vs. command line

Sendmail from cron vs. command line

Post by Michael Tosc » Fri, 24 Jun 2005 05:07:17




> I have a ksh script which calls a Perl script using /usr/lib/sendmail
> to send mail. When I run the Perl script from the command line it seems
> to use my /etc/mail/sendmail.cf but when running the Perl script
> through the ksh script in cron it does not. I can tell this because the
> return path is not set properly when the script runs from cron. Here is
> the ksh script:

> #!/usr/bin/ksh
> #set -x
> cd /export/home2/spiderman/queue

> chmod 777 *.email

> PETER=`ls -1 [0-9]*email | wc -l `

> if [ $PETER -ne 0 ]
> then
> for i in `ls -1 [0-9]*email`
> do
>    MDATE=`date +%d%b%y-%H%M%S`
>    LOGFILE=/export/home2/spiderman/logs/PRO-email.sent.log
>    echo " PROFILE MAILER START" >> $LOGFILE
>    echo " ============================================== " >> $LOGFILE
>    cat $i  >> $LOGFILE
>    /usr/bin/perl $i   2>> $LOGFILE
>    echo " ============================================== " >> $LOGFILE
>    echo " PROFILE MAILER SENT" >> $LOGFILE
>    rm $i
> done
> fi

> Here is an example of the Perl script:

> #!/usr/bin/perl

> open(SENDMAIL, "|/usr/lib/sendmail -oi -t") or die "Can't open
> sendmail: $!\n";
> print SENDMAIL << "EOF";


> Subject: Blah Blah
> Some text

> Thank You
> EOF
> close(SENDMAIL) or warn "sendmail did not close nicely";

> Any ideas why this is not getting the proper sendmail.cf through cron?

Hi,

/usr/lib/sendmail will certainly use its sendmail.cf file.
The error must be somewhere else.

Consider this version:

cd /export/home2/spiderman/queue
MDATE=...
LOGFILE=...
# turn shell expansion on in case it was off
set +f
for i in [0-9]*email
do
  # ensure this is a readable file:
  [ -f "$i" ] || continue
  # probably not needed:
  # chmod 777 "$i"
  echo " PROFILE MAILER START"
  echo " ============================================== "
  cat "$i"
  /usr/bin/perl "$i" 2>&1
  # sendmail is CPU-intensive - give the system a breath
  sleep 1
  rm -f "$i"
  echo " ============================================== "
  echo " PROFILE MAILER SENT"
done >> $LOGFILE
exit 0

If I understand right, the script should execute whatever
it finds with a /usr/bin/perl interpreter.
A bit strange, and a bit risky...

What do you mean by "return path"?

--

 
 
 

1. cron vs command-line

Hi expert,
    I have a short script which perform a "ping" test every minute. It
work perfectly in command line mode and report the appropriate "ping"
results.

    However, when I put it in as a "cron" job, it never reports the
correct "ping" status. It always reports the host is DEAD, even if it's
ALIVE ......

    Please help. Thanks.

    Here's the script:

#!/bin/sh

# this script can run in command line, but won't work in crontab

filename=/tmp/abc_ping_status
ping abc 3
if [ $? -eq 0 ]; then
   printf "abc ALIVE \n" >> $filename
else
   printf "abc DEAD \n" >> $filename
fi

Regards,
Francis.

2. Solaris 2.4

3. Desktop vs. Command Line, was Linux vs. OS/2

4. aic7xxx module in RedHat Linux 7.1?

5. Boot blocks when it reaches inetd cron sendmail line

6. Solaris TCP stack adjustments

7. cron fails; command line OK

8. What linux is best to run os Sun IPX (Sun4c)

9. Command Line and Cron

10. How to tell if script is run from cron or command line?

11. Command Line Script runs fine get bad substititon from cron

12. Crond help: Script Runs from command line, but not from cron