4

I'm trying to run a sendmail command in a Red-hat Linux environment on a bash shell script through a cronjob. I can run this script successfully when it is ran manually and every other job within the shell runs correctly other than the mailing part.I have never used sendmail and am not sure if I need to restructure how it is being presented.

I have tried mail and mailx. I am able to send the emails but the log file contain many weird characters that it put the text format into a att00001.bin attachment on the email which I do not want. The sendmail command seems to be the only one that doesn't send an attachment when ran manually. Other cron jobs works correctly and are able to send emails they just do not have the special characters in the log file.

echo '##################################################'
date
echo '##################################################'

#Run Script and write to log file
/comp/gfb281m.sh > /usr/local/bin/oracle/getload/getload.log 2>&1

#Send log file to developer group
(echo "Subject:GetLoad Shell"; echo; cat 
/usr/local/bin/oracle/getload/getload.log) | sendmail -v 
exampleEmail@outlook.com exampleEmail2@mail.mil

When ran this cron job should send the contents of the getload.log file to a group a of users.

NeoAer
  • 327
  • 3
  • 15
  • 1
    Any messages in wherever cron logs to on RedHat? – tink Feb 05 '19 at 22:11
  • Stupid me I just told the cron to write itself a log file when ran and saw that it didn't understand where to find the sendmail command. Thanks for hint on the logs sadly I should of know this. – NeoAer Feb 05 '19 at 22:18

2 Answers2

5

Fixed the issue thanks to another source. I was not using the sendmail's full path. I was just stating "| sendmail -v email" and not sendmails full path which was "/usr/sbin/sendmail" for me. Not sure if links are allowed here but below is where I found the answer.

https://www.unix.com/red-hat/271632-bash-sendmail-command-not-found.html

NeoAer
  • 327
  • 3
  • 15
4

crontab sets PATH to /usr/bin:/bin. To avoid typing absolute command names like /etc/sbin/sendmail you can set up the PATH in you crontab:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
*/30 * * * * sendmail user@example.com%subject: Sample email%%Email body%
builder-7000
  • 7,131
  • 3
  • 19
  • 43