Good Day Everyone,
I have successfully implemented the smtp_send.pl script on my ESX 3.5 Server. I script executes perfectly from the command line, but for some reason, the cron fails to execute the script. Based on research, it appears that either file permissions or environment PATH variables are the likely suspects. On the perl script i have changed the permissions to 777 so any user can execute. Here is what my crontab looks like
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
33 10 * * * printf "Test from ESX Server" | /usr/local/bin/smtp_send.pl -t vmbackup@firstcomm.com -s "VMWare Backup Test Email ESX Server" -f esx1@global-com.com -r 172.16.6.106
I did an output to a text file for debugging purposes at /tmp/cronerrors.txt. Here is the output which appears normal....
to: vmbackup@firstcomm.com
subject: VMWare Backup Test Email ESX Server
attach: none
The perl script requires a module, Lite.pm, which is placed in the proper directory. However here are the permissions on the module:
-rw-rr 1 root root 89380 Apr 24 2003 Lite.pm
Can someone assist me with this?
Thanks
Stevester
The script is executed or not?
You say that the script failed, but also that the log file is correct.
What do you see in your /var/log/cron file and in the SMTP server log file?
Andre
Well script runs from command line. No problem. Now when I try to execute it via cron job, no email gets sent out. Now if I redirect it to log file, then the script partially executes. The printf or echo statements in the script runs as shown by the crontaberr.txt but no email is sent which I would like to happen.
Stevester
Here is what is /var/log/cron: The last attempt to test cron was at 11:46am (at bottom of the message shwon below)
Sep 6 02:01:01 esx1 crond[22302]: (root) CMD (run-parts /etc/cron.hourly)
Sep 6 03:01:01 esx1 crond[22349]: (root) CMD (run-parts /etc/cron.hourly)
Sep 6 04:01:01 esx1 crond[22396]: (root) CMD (run-parts /etc/cron.hourly)
Sep 6 04:02:01 esx1 crond[22443]: (root) CMD (run-parts /etc/cron.daily)
Sep 6 04:22:01 esx1 crond[22640]: (root) CMD (run-parts /etc/cron.weekly)
Sep 6 05:01:01 esx1 crond[28784]: (root) CMD (run-parts /etc/cron.hourly)
Sep 6 06:01:01 esx1 crond[28831]: (root) CMD (run-parts /etc/cron.hourly)
Sep 6 07:01:01 esx1 crond[28878]: (root) CMD (run-parts /etc/cron.hourly)
Sep 6 08:01:01 esx1 crond[28925]: (root) CMD (run-parts /etc/cron.hourly)
Sep 6 08:38:15 esx1 crontab[29013]: (root) BEGIN EDIT (root)
Sep 6 08:42:44 esx1 crontab[29013]: (root) END EDIT (root)
Sep 6 08:42:48 esx1 crontab[29015]: (root) BEGIN EDIT (root)
Sep 6 08:45:00 esx1 crontab[29015]: (root) REPLACE (root)
Sep 6 08:45:00 esx1 crontab[29015]: (root) END EDIT (root)
Sep 6 08:45:01 esx1 crond[1905]: (root) RELOAD (cron/root)
Sep 6 08:45:10 esx1 crontab[29018]: (root) BEGIN EDIT (root)
Sep 6 08:45:37 esx1 crontab[29018]: (root) REPLACE (root)
Sep 6 08:45:37 esx1 crontab[29018]: (root) END EDIT (root)
Sep 6 08:46:01 esx1 crond[1905]: (root) RELOAD (cron/root)
Sep 6 08:46:01 esx1 crond[29023]: (root) CMD (printf "Test from ESX Server" | /usr/local/bin/smtp_send.pl -t vmbackup@firstcomm.com -s "VMWare Backup Test Email ESX Server" -f esx1@global-com.com -r 172.16.6.106)
Sep 6 08:57:06 esx1 crontab[29027]: (root) BEGIN EDIT (root)
Sep 6 08:57:29 esx1 crontab[29027]: (root) REPLACE (root)
Sep 6 08:57:29 esx1 crontab[29027]: (root) END EDIT (root)
Sep 6 08:58:01 esx1 crond[1905]: (root) RELOAD (cron/root)
Sep 6 09:01:01 esx1 crond[29031]: (root) CMD (run-parts /etc/cron.hourly)
Sep 6 09:13:59 esx1 crontab[29087]: (root) BEGIN EDIT (root)
Sep 6 09:15:08 esx1 crontab[29087]: (root) REPLACE (root)
Sep 6 09:15:08 esx1 crontab[29087]: (root) END EDIT (root)
Sep 6 09:15:12 esx1 crontab[29089]: (root) BEGIN EDIT (root)
Sep 6 09:15:48 esx1 crontab[29089]: (root) REPLACE (root)
Sep 6 09:15:48 esx1 crontab[29089]: (root) END EDIT (root)
Sep 6 09:16:01 esx1 crond[1905]: (root) RELOAD (cron/root)
Sep 6 09:16:45 esx1 crontab[29094]: (root) BEGIN EDIT (root)
Sep 6 09:16:58 esx1 crontab[29094]: (root) END EDIT (root)
Sep 6 09:17:01 esx1 crond[29098]: (root) CMD (printf "Test from ESX Server" | /usr/local/bin/smtp_send.pl -t vmbackup@firstcomm.com -s "VMWare Backup Test Email ESX Server" -f esx1@global-com.com -r 172.16.6.106)
Sep 6 09:41:47 esx1 crontab[29102]: (root) BEGIN EDIT (root)
Sep 6 09:42:25 esx1 crontab[29102]: (root) REPLACE (root)
Sep 6 09:42:25 esx1 crontab[29102]: (root) END EDIT (root)
Sep 6 09:43:01 esx1 crond[1905]: (root) RELOAD (cron/root)
Sep 6 09:51:52 esx1 crontab[29127]: (root) BEGIN EDIT (root)
Sep 6 09:52:29 esx1 crontab[29127]: (root) REPLACE (root)
Sep 6 09:52:29 esx1 crontab[29127]: (root) END EDIT (root)
Sep 6 09:53:01 esx1 crond[1905]: (root) RELOAD (cron/root)
Sep 6 09:53:01 esx1 crond[29133]: (root) CMD (printf "Test from ESX Server" | /usr/local/bin/smtp_send.pl -t vmbackup@firstcomm.com -s "VMWare Backup Test Email ESX Server" -f esx1@global-com.com -r 172.16.6.106)
Sep 6 10:01:01 esx1 crond[29139]: (root) CMD (run-parts /etc/cron.hourly)
Sep 6 10:11:39 esx1 crontab[29190]: (root) BEGIN EDIT (root)
Sep 6 10:12:08 esx1 crontab[29190]: (root) REPLACE (root)
Sep 6 10:12:08 esx1 crontab[29190]: (root) END EDIT (root)
Sep 6 10:12:23 esx1 crontab[29193]: (root) BEGIN EDIT (root)
Sep 6 10:12:44 esx1 crontab[29193]: (root) REPLACE (root)
Sep 6 10:12:44 esx1 crontab[29193]: (root) END EDIT (root)
Sep 6 10:13:01 esx1 crond[1905]: (root) RELOAD (cron/root)
Sep 6 10:13:01 esx1 crond[29198]: (root) CMD (printf "Test from ESX Server" | /usr/local/bin/smtp_send.pl -t vmbackup@firstcomm.com -s "VMWare Backup Test Email ESX Server" -f esx1@global-com.com -r 172.16.6.106)
Sep 6 10:16:45 esx1 crontab[29202]: (root) BEGIN EDIT (root)
Sep 6 10:18:05 esx1 crontab[29202]: (root) REPLACE (root)
Sep 6 10:18:05 esx1 crontab[29202]: (root) END EDIT (root)
Sep 6 10:19:01 esx1 crond[1905]: (root) RELOAD (cron/root)
Sep 6 10:19:01 esx1 crond[29206]: (root) CMD (printf "Test from ESX Server" | /usr/local/bin/smtp_send.pl -t vmbackup@firstcomm.com -s "VMWare Backup Test Email ESX Server" -f esx1@global-com.com -r 172.16.6.106 >/tmp/cronerror.txt)
Sep 6 10:31:01 esx1 crond[29216]: (CRON) DEATH (can't lock /var/run/crond.pid, otherpid may be 1905: Resource temporarily unavailable)
Sep 6 10:32:08 esx1 crond[29232]: (CRON) STARTUP (V5.0)
Sep 6 10:32:20 esx1 crontab[29235]: (root) BEGIN EDIT (root)
Sep 6 10:32:36 esx1 crontab[29235]: (root) REPLACE (root)
Sep 6 10:32:36 esx1 crontab[29235]: (root) END EDIT (root)
Sep 6 10:32:49 esx1 crontab[29238]: (root) BEGIN EDIT (root)
Sep 6 10:32:53 esx1 crontab[29238]: (root) END EDIT (root)
Sep 6 10:33:01 esx1 crond[29232]: (root) RELOAD (cron/root)
Sep 6 10:33:01 esx1 crond[29242]: (root) CMD (printf "Test from ESX Server" | /usr/local/bin/smtp_send.pl -t vmbackup@firstcomm.com -s "VMWare Backup Test Email ESX Server" -f esx1@global-com.com -r 172.16.6.106 >/tmp/cronerror.txt)
Sep 6 10:48:12 esx1 crontab[29245]: (root) BEGIN EDIT (root)
Sep 6 10:49:12 esx1 crontab[29245]: (root) END EDIT (root)
Sep 6 10:55:41 esx1 crontab[29252]: (root) BEGIN EDIT (root)
Sep 6 11:01:01 esx1 crond[29255]: (root) CMD (run-parts /etc/cron.hourly)
Sep 6 11:34:14 esx1 crontab[29252]: (root) END EDIT (root)
Sep 6 11:40:10 esx1 crontab[29309]: (root) BEGIN EDIT (root)
Sep 6 11:40:43 esx1 crontab[29309]: (root) REPLACE (root)
Sep 6 11:40:43 esx1 crontab[29309]: (root) END EDIT (root)
Sep 6 11:41:01 esx1 crond[29232]: (root) RELOAD (cron/root)
Sep 6 11:41:25 esx1 crontab[29312]: (root) BEGIN EDIT (root)
Sep 6 11:44:44 esx1 crontab[29312]: (root) REPLACE (root)
Sep 6 11:44:44 esx1 crontab[29312]: (root) END EDIT (root)
Sep 6 11:45:01 esx1 crond[29232]: (root) RELOAD (cron/root)
Sep 6 11:45:03 esx1 crontab[29318]: (root) BEGIN EDIT (root)
Sep 6 11:45:25 esx1 crontab[29318]: (root) REPLACE (root)
Sep 6 11:45:25 esx1 crontab[29318]: (root) END EDIT (root)
Sep 6 11:46:01 esx1 crond[29232]: (root) RELOAD (cron/root)
Dont know where the SMTP log is?
Dont know where the SMTP log is?
What SMTP are you using? You have to watch there to see if a connection is opened.
PS: if you have ESX you must also open the outgoing 25 TCP port.
Andre
I am using a script called: smtp_send.pl. It is placed in /usr/local/bin. The script requires a perl module: Lite.pm. This is placed in /usr/lib/perl5/5.8.0/MIME. The smtp_send.pl script has been made executable. The firewall has been opened on port 25 already which explains why i can send it successfully from command line. I am starting to think something in the smtp_send.pl needs to be changed.
Here is smtp_send.pl code:
#!/usr/bin/perl -w
======================================================================
#
Perl Source File -- Created with SAPIEN Technologies PrimalScript 3.1
#
NAME: smtp_send.pl
#
ORIGINAL AUTHOR: Scott Herold , RapidApp
ORIGINAL DATE : 11/30/2004
#
MODIFY AUTHOR: Jeremy Pries, Xcedex (jpries-at-xcedex-dot-com)
MODIFY DATE : 4/20/2005
#
MODIFY AUTHOR: Duncan Epping, Yellow-Bricks.com
MODIFY DATE : 9/7/2007
MODIFIED: Line 99 changed TEXT to TEXT/HTML
#
PURPOSE: This is a small script that can send emails through an
external smtp gateway. This is useful when sending log files from an
ESX host to an administrator or group on a scheduled basis.
#
Handles piped (|) input, command line message content and file attachments
#
PREREQUESITES: The MIME-Lite module is required for this script
to function.
#
#
This module must be placed in the following directory of your ESX host:
(Note, the directory will need to be created and is case sensative)
#
/usr/lib/perl5/5.6.1/MIME
#
#
======================================================================
use MIME::Lite;
use Sys::Hostname;
use Getopt::Long;
Variables to configure
#
From Address. By default it just uses a hostname lookup. You may change this to something else if desired.
my $fromAddress = hostname();
Set your smarthost here
my $smartHost = "smarthost.example.com";
Command Line Arguments
if (@ARGV < 2) {
print "\n";
print "-Enclose any options that contains spaces in quotes\n";
print "-All options may be shortened to one character. Ex. -t instead of -toAddress\n\n";
print "Options:\n";
print " -toAddress rcpt to address (required)\n";
print " -subject subect (required)\n";
print " -messageBody body (optional)\n";
print " -attach full path to attachment (optional)\n";
print " -fromAddress mail from address (optional)\n";
print " -relay smarthost/relayhost used to deliver mail. (optional)\n\n";
print "-If no fromAddress is specified, the address $fromAddress will be used\n\n";
print "-If no relay is specified, the variable $smartHost in the script is used.\n";
print " You may wish to change the value of this variable to prevent need to specify it on the command line.\n\n";
print "As of version 0.2, script will handle message body input via a pipe. If input is received via a pipe\n";
print " and message body on command line, the command line text will precede the pipe input in the body.\n";
print "\n";
exit(1);
}
my $toAddress = '';
my $subject = '';
my $messageBody = '';
my $attach = 'none';
GetOptions ('toAddress=s' => \$toAddress,'subject=s' => \$subject, 'messageBody=s' => \$messageBody, 'attach=s' => \$attach, 'fromAddress=s' => \$fromAddress, 'relay=s' => \$smartHost);
unless (-t) {
$messageBody = $messageBody . "\n";
while ( $line = ) {
chomp $line;
$messageBody = $messageBody . $line . "\n";
}
}
print "smartHost: $smartHost\n";
print "to: $toAddress\n";
print "subject: $subject\n";
print "attach: $attach\n";
Default Email header stuff
$msg = MIME::Lite->new(
From =>$fromAddress,
To =>$toAddress,
Subject =>$subject,
Type =>'multipart/mixed'
);
The text message portion of the email. Remember \n to break lines
$msg->attach(Type =>'TEXT/HTML',
Data =>$messageBody
);
Attach a file if necessary
if ($attach ne "none") {
Path is full path to file, Filename is file name as attached (Can be
different than the source file name)
$msg->attach(Type =>'applications/zip',
Path =>$attach
);
}
Mail type and SMTP server. Send email based off those settings
MIME::Lite->send('smtp', $smartHost);
$msg->send;
In addition my enviroment is ESX 3.5 not ESX Server 4.0 (Yes I posted in VI3 forum, but I thought I would get more responses from this forum which is what is happening)
You must see on "smarthost.example.com" the see SMTP log.
Another test that you can do is create a simple bash script, make it executable and put in /etc/cron.hourly to see if it works.
Andre
Since you mentioned that the scripts are executing from the command line. Can you try and paste your entry cron entry (minus the time ofcourse!), just the command which you would execute from console into a file say script.sh and then just call that file in the cron.
You will also have to give permissions to execute to that file...if you run by root then chmod 700 would suffice.
Just did that 5 mins ago and it worked. Having cron execute a bash script - email.sh with the commands worked.
For some reason having cron execute doesn't work but that's okay. Its now working simply having cron run a shell script
Thanks Everyone
Stevester