Operating System - HP-UX
1834434 Members
2873 Online
110067 Solutions
New Discussion

Re: ELM can't send attach if started thru CRON

 
SOLVED
Go to solution
Vlad_11
Frequent Advisor

ELM can't send attach if started thru CRON

Greetings,
I have a shell, that sucesufully sends 2 email with attach and 1 plain if started on prompt line.
Same shell started thru cron, can send only 1 plain email, no any traces of those 2 with attachements.
I'm using:
elm -s " $FSUB $SUBJECT" -a $MAILTO < temp3 >>$LOGFIL
here is ll for my shell:
-rwxr-xr-x 1 rpgmail users 4690 Mar 10 17:18 proc

Probably there is some mess with cron authority...



Another interesting issue that name of attach I see like in my Outlook, and when I tried to open this file I get a correct name: e.g. Trades.txt. But probably it's W* Outlook issue.

Thanks to all.
beer or not beer
10 REPLIES 10
Pete Randall
Outstanding Contributor
Solution

Re: ELM can't send attach if started thru CRON

How about trying a full path name for the attachment?


Pete

Pete
A. Clay Stephenson
Acclaimed Contributor

Re: ELM can't send attach if started thru CRON

First of all, cron has a very sparse environment so that you must explicitly set and export any needed environment variables in the script called by cron. You probably need to create a wrapper scripper to set and export variables. Second, when run from the command line, you MUST have a .elm directory
in the cron user's home directory before running elm. Elm run interactively will automatically create this directory but the command-line invocation will not.
If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: ELM can't send attach if started thru CRON

You probaly have an environment problem. If this script has other commands, chances are elm or these commands simply is not on the path.

I'm attaching a production sendmail attachment script that works well with cron.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Vlad_11
Frequent Advisor

Re: ELM can't send attach if started thru CRON

Thanks,
Pete: I do use full path, and I see my proc was ran thru timestamps, log file updates, plain email sent. The only problem that I can't recieve emails with attach.

Clay:
I have .elm, and I 100% sucesfully rinning my ./proc from prompt line, the problem with running it thru cron.
Will check you info regarding Variables.

Thanks all
Vlad
beer or not beer
Vlad_11
Frequent Advisor

Re: ELM can't send attach if started thru CRON

Thanks, Steven
I have to stick with elm, don't have a choice. Just to specified a full path to all commands, still same result.
I'm checking a status after execution of each command, and it's = 0 ???
Can't figure out, do I need do Export all $var??


Vlad
beer or not beer
Pete Randall
Outstanding Contributor

Re: ELM can't send attach if started thru CRON

Yes, I would export all variables. How about posting the script so we can get a better idea what we are dealing with?


Pete

Pete
Vlad_11
Frequent Advisor

Re: ELM can't send attach if started thru CRON

I'm attaching my aaproc, function it's where I'm stuck.

This proc takes control file from ftp dir, extract attach file name, email address from this control file, check it size, zip/nozip depending on size, then send file out.

There is line:
cd $WDIR that should solve all envrironmental problems, as I thought...
beer or not beer
Pete Randall
Outstanding Contributor

Re: ELM can't send attach if started thru CRON

Well right off the bat, I have to wonder where tempp1 and tempp2 are being set. There may be others that may be set when you run this from the command line but are not because of cron's minimal environement. All these things need to be defined.


Pete

Pete
Vlad_11
Frequent Advisor

Re: ELM can't send attach if started thru CRON

Thanks, Pete

I do cd $WDIR at the very beginning. I can see both tempp* there after execution.

Vlad
beer or not beer
A. Clay Stephenson
Acclaimed Contributor

Re: ELM can't send attach if started thru CRON

When I look at your script I see several things that bother me:

1) Inconsistant pathname conventions
sometimes 'elm -s' and sometines '/usr/local/bin/elm -s'. I also see one that looks very suspicious 'usr/bin/unix2dos'.

You really should handle it via something like this near the top of your script:

PATH=${PATH}:/usr/local/bin # + any other needed
export PATH

You then don't need full path names. I good idea would be to match ${PATH} when you are running from a shell prompt.


2) I really dislike your hard-coded temp file names; the better answer is something like this:

TDIR=${TMPDIR:-/var/tmp}
T1=${TDIR}/X${$}_1.tmp
T2=${TDIR}/X${$}_2.tmp

and so on and then use ${T1}, ${T2} as your files.

You also need a trap statement that rm's these files upon exit or receipt of a signal.
Temp file names like this will prevent collisions when multiple instances of the same script are running. It's just good practice.

3) You do many operations without testing the result, blindly assuming all is well.

e.g.

cd ${WDIR}
# you should add a test like this:
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "${0}: cd to \"${WDIR}\" failed; status : ${STAT}" >&2
exit ${STAT}
fi

If it ain't broke, I can fix that.