3 Replies Latest reply on Feb 6, 2011 8:27 PM by Nik

    Cronjob sending Email successfully with exec failed. errno=2 on log

    836793
      Hi,

      We are using a cron job to send emails about status. Due to security restrictions we are not running any SMTP client in the application server. In stead we are using a separate SMTP server and directly sending the mail content with from and to address to SMTP servers 25 port.

      We are using the below code to achieve this.

      exec 3<>/dev/tcp/$smtp/25
      + cat << EOF >&3+
      HELLO `hostname`
      MAIL From: <$from>
      RCPT To: <$email>
      RCPT To: <$email2>
      DATA
      Subject: $summary_subj
      Reply-To: <$from>
      +`mail_summary_body`+
      +.+
      QUIT
      EOF
      + cat <&3+

      It successfully executes to job and sends us emails.

      However, in /var/cron/log it sends an error.

      +> CMD: /mnt/xxxx/xxxxx/xxxx/xxxx.sh+
      +> root 14286 c Fri Feb 4 06:33:00 2011+
      +< root 14286 c Fri Feb 4 06:33:00 2011+
      exec failed. errno=2.


      Can you please let me know what is going on. Why am i seeing errors when the job is running just fine.
        • 1. Re: Cronjob sending Email successfully with exec failed. errno=2 on log
          abrante
          Hmm, no idea as such, but i though

          exec 3/dev/tcp/$smtp/25

          was ksh syntax which worked only in ksh? (and possibly bash). Whereas most scripts ran from crontab are executed in the quite dumb /bin/sh with a quite basic environment, perhaps this could cause this error?

          Also, according to your cron/log, the cronjob takes 0 seconds, which is suspiciously fast..

          .7/M.
          • 2. Re: Cronjob sending Email successfully with exec failed. errno=2 on log
            836793
            Thanks Abrante.

            I have used bash scripts in and they run just fine in cron.

            However, I did see in the man page of exec that they have mentioned options only for "sh/csh/ksh" but not bash. Which is a bit odd. Still, I don't think this can be a reason. As i ran exec in bash and runs fine.

            Appreciate if you can find a way of finding what exactly is the problem.

            Thanks.

            Smruti
            • 3. Re: Cronjob sending Email successfully with exec failed. errno=2 on log
              Nik
              Hello!
              It war very usefull and intresting found for me BASH capabilities work with socket.

              I try use your commands for script but shell found some errors.

              For test I use next script:

              #!/bin/bash
              ###
              #Define Environment
              ###

              exec 3<>/dev/tcp/$smtp/25
              cat << EOF >&3
              HELO $hostname
              MAIL From: <$from>
              RCPT To: <$email>
              DATA
              Subject: $summary_subj
              Reply-To: <$from>

              $mail_summary_body
              .
              QUIT
              EOF
              cat <&3 > $LOG

              #####################
              What found:
              1) #!/bin/bash - Critical. becouse /bin/sh can't use tcp socket
              2) I can't reproduce this error when start this script via cron. It's work fine.

              3) In case of error's Log look like
              > CMD: /tmp/n2
              root 7770 c Mon Feb 7 01:22:00 2011
              < root 7770 c Mon Feb 7 01:22:00 2011 rc=1

              (Without exec ..... )

              4) When cron jobs generate any output to stdout, stderr - this iutput put to E-mail of users who start this cron jobs.
              So try look mail for root. It can content more details about problem.

              Regards.