sendmail from cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sendmail from cron
# 1  
Old 09-13-2012
sendmail from cron

Hi all,

Recently i started using sendmail instead of mutt to send the email .
In one script i have both sendmail and mutt included and they both give different emails.



Code:
##some HTML creation
1) First email
cat - $data_dir/TheMailer.txt <<EOF | sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: $SUBJECT
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
EOF

2) Second email
cat $data_dir/TheMailer2.txt | mutt -s "$SUBJECT2" $MAILTO

when i run the above script manually i get the both emails , but when i cron it i get only second email ie email from mutt and not the sendmail.

anything being missed or anything specific needs to be set for sendmail to work from cron.

also how to attach file in sendmail.
Code:
i tried this

cat - $data_dir/TheMailer.txt ; $data_dir/file.txt <<EOF | sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: $SUBJECT
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
EOF

cat - $data_dir/TheMailer.txt <<EOF | sendmail -oi -t
From: ${MAILFROM}
To: ${MAILTO}
Subject: $SUBJECT
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
uuencode $data_dir/file.txt 
MIME-Version: 1.0
EOF

both did not work for me.

Thanks in advance for the help.
# 2  
Old 09-13-2012
Are all the env variables loaded for cron ? ( Knows nothing about your environment you know...)
# 3  
Old 09-13-2012
as i dont know any specific env variable, here is the list.

Code:
[admin@db user]$ printenv
HOSTNAME=db.net
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
QTDIR=/usr/lib64/qt-3.3
USER=admin
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
SUDO_USER=user
SUDO_UID=505
USERNAME=root
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib64/ccache:/sbin:/bin:/usr/sbin:/usr/bin
MAIL=/var/spool/mail/user
PWD=/home/user
LANG=en_US.UTF-8
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SHLVL=1
SUDO_COMMAND=/bin/su admin
HOME=/home/admin
LOGNAME=admin
CVS_RSH=ssh
LESSOPEN=|/usr/bin/lesspipe.sh %s
SUDO_GID=505
G_BROKEN_FILENAMES=1
_=/usr/bin/printenv
[admin@db user]$

# 4  
Old 09-13-2012
The point is cron knows none of then and $PATH=/bin:/usr/bin
So what you use that ist not in $PATH needs to be set, the same goes for all variables...
e.g. Where do you get $data_dir set ?

a way to see if that is the issue: when you execute both series of commands /scripts, they work in interactive?
So you have in your environment wht is expected to run the scripts...

You could copy you .profile or whatever you use to profile_mailtest and source it in your shellscript at the beginning:
Code:
. /<path_to>profile_mailtest

#the space after dot IS important!
Comment out before all reference to keyboard and terminal since there are none otherwise you will get cron complaining...
# 5  
Old 09-13-2012
First look in unix mail for the owner of the cron. If there is an error message, it should be there.

Also try a one-off cron containing only "printenv" and if that fails, try just "env". Save the output to a file so you can read it. That will tell you what you environment is like in cron.
# 6  
Old 09-13-2012
Thanks guys for pointing out the env variables
i changed the the script to

Code:
cat - $data_dir/TheMailer.txt <<EOF | /usr/sbin/sendmail -oi -t 
From: ${MAILFROM} 
To: ${MAILTO} 
Subject: $SUBJECT 
Content-Type: text/html; charset=us-ascii 
Content-Transfer-Encoding: 7bit 
MIME-Version: 1.0 
EOF

and i worked from cron .

for the second part , attaching a file using sendmail looks like complex from reading lot of other posts.

Best tutorial i found is
Sending Emails With Sendmail - Part 2 - Linux Tutorials, Guides and Tips - CODECALL

Is there any easy way for attaching a file like using uuencode

Thanks




Sending Emails With Sendmail - Part 2 - Linux Tutorials, Guides and Tips - CODECALL
# 7  
Old 09-13-2012
/usr/bin/mailx is an interface to sendmail. Most UNIXes with sendmail have mailx

Code:
uuencode somefile name-of-file-on-email.txt | mailx -s 'subject' me@myplace.com

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Clarifying sendmail configuration - sendmail-client offline

Hi all, I have read about sendmail running as 2 separate process. 1 as a MSP, and the other as the real daemon or MTA. In my current configuration, the sendmail-client is disabled. Both submit.cf and sendmail.cf are left as default untouch I do not specified any mailhost... (3 Replies)
Discussion started by: javanoob
3 Replies

2. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

3. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

4. UNIX for Advanced & Expert Users

Sendmail questions, SCO 5.0.6 sendmail 8.11.0

I am running SCO 5.0.6 and using sendmail 8.11.0 and having issues with smtp authentication. When trying to send mail the following message will kick back. (reason: 530 5.7.1 Authentication required) 530 5.7.1 Authentication required Not sure what needs to be tweeked in sendmail.cf but I... (1 Reply)
Discussion started by: ziggy6
1 Replies

5. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

6. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

7. UNIX for Dummies Questions & Answers

How are cron.allow and cron.deny read?

Hi, all! I was working on my Debian, minding my own business but then I wanted to see what happened if the same user was included on both cron.allow and cron.deny :p I would have bet that cron.deny was going to override cron.allow for security reasons, but my computer proved me wrong:... (3 Replies)
Discussion started by: pereyrax
3 Replies

8. Solaris

User entry in both cron.allow and cron.deny

Hello All, Anybody please help me to know ,what happens when a user having entry in both cron.allow and cron.deny files.Wheather the user will be able to access the crontab??? Thanks in advance Vaisakh (5 Replies)
Discussion started by: ksvaisakh
5 Replies

9. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

10. AIX

AIX and cron logs filtering ?: /etc/cronlog.conf, /var/adm/cron/log

Hi, I can use 'crontabs –e' and do all the scheduling I like. However I would like to auto send myself just the cronjobs logs that fail. That is to say the PIDs that fail and the related lines with those PID’s only. (Not the full set of logs) Has anyone done this work? Or does an AIX 5.3 tool... (0 Replies)
Discussion started by: Keith Johnson
0 Replies
Login or Register to Ask a Question