Loading ...
Sorry, an error occurred while loading the content.

Re: [openslug] Send mail with nail in crontab

Expand Messages
  • tkayna
    Thanks, It returns me this : $ cat /tmp/myLog.err /usr/lib/sendmail: No such file or directory . . . message not sent. And I have this in nail bin : $strings
    Message 1 of 10 , Nov 22, 2009
    • 0 Attachment
      Thanks,

      It returns me this :
      $ cat /tmp/myLog.err
      /usr/lib/sendmail: No such file or directory
      . . . message not sent.

      And I have this in nail bin :
      $strings /usr/bin/nail | grep sendmail
      sendmail
      /usr/lib/sendmail

      But I don't understand why it works in shell.

      Thank you for your help

      --- In nslu2-linux@yahoogroups.com, "rolandkbs" <roland.krebs@...> wrote:
      >
      > I don't see the cause, but maybe I can help you to find it:
      > Add to the end of your crontab line the following
      > >/tmp/myLog.out 2>/tmp/myLog.err
      >
      > By inspecting the two files after the defined time has passed you will most probably find the problem.
      >
      > regards, Roland
      >
      > --- In nslu2-linux@yahoogroups.com, "tkayna" <tkayna@> wrote:
      > >
      > > Hello,
      > >
      > > I made un script to send mail.
      > > My script works executing in shell but not in crontab.
      > > I also add full path for binaries but it's the same.
      > >
      > > Can someone help me ?
      > >
      > > ***BASH SCRIPT send_mail.sh :
      > >
      > > #!/opt/bin/bash
      > >
      > > nail='/usr/bin/nail'
      > > sleep='/bin/sleep'
      > > echo='/bin/echo'
      > >
      > >
      > > function mail_status ()
      > > {
      > > ${sleep} 1
      > > ${echo} $1 $2 | ${nail} -s "save_sites_SQL_$1_$2" myemail@;
      > > #echo $? > /tmp/testestest_sendmail.txt
      > > }
      > >
      > > #### DEBUG TESTS ####
      > >
      > > mail_status "Test" "succes";
      > >
      > > ***CRONTAB LINE :
      > >
      > > 33 23 * * * /opt/bin/bash /temp/testmail/send_mail.sh
      > >
      >
    • rolandkbs
      I don t know nail , so I m just guessing: Nail tries to find sendmail in the path ($PATH) and if it s not found there then in /usr/lib. So it looks like 1.
      Message 2 of 10 , Nov 22, 2009
      • 0 Attachment
        I don't know 'nail', so I'm just guessing:
        Nail tries to find sendmail in the path ($PATH) and if it's not found there then in /usr/lib. So it looks like
        1. your path ($PATH) is different from the crontab's, and
        2. sendmail is not in /usr/lib, but maybe /usr/sbin

        If nail has some configuration files, then you can probably set the sendmail-location there, if not then you can extend $PATH in your bash-script.

        regards, Roland

        --- In nslu2-linux@yahoogroups.com, "tkayna" <tkayna@...> wrote:
        >
        > Thanks,
        >
        > It returns me this :
        > $ cat /tmp/myLog.err
        > /usr/lib/sendmail: No such file or directory
        > . . . message not sent.
        >
        > And I have this in nail bin :
        > $strings /usr/bin/nail | grep sendmail
        > sendmail
        > /usr/lib/sendmail
        >
        > But I don't understand why it works in shell.
        >
        > Thank you for your help
        >
        > --- In nslu2-linux@yahoogroups.com, "rolandkbs" <roland.krebs@> wrote:
        > >
        > > I don't see the cause, but maybe I can help you to find it:
        > > Add to the end of your crontab line the following
        > > >/tmp/myLog.out 2>/tmp/myLog.err
        > >
        > > By inspecting the two files after the defined time has passed you will most probably find the problem.
        > >
        > > regards, Roland
        > >
        > > --- In nslu2-linux@yahoogroups.com, "tkayna" <tkayna@> wrote:
        > > >
        > > > Hello,
        > > >
        > > > I made un script to send mail.
        > > > My script works executing in shell but not in crontab.
        > > > I also add full path for binaries but it's the same.
        > > >
        > > > Can someone help me ?
        > > >
        > > > ***BASH SCRIPT send_mail.sh :
        > > >
        > > > #!/opt/bin/bash
        > > >
        > > > nail='/usr/bin/nail'
        > > > sleep='/bin/sleep'
        > > > echo='/bin/echo'
        > > >
        > > >
        > > > function mail_status ()
        > > > {
        > > > ${sleep} 1
        > > > ${echo} $1 $2 | ${nail} -s "save_sites_SQL_$1_$2" myemail@;
        > > > #echo $? > /tmp/testestest_sendmail.txt
        > > > }
        > > >
        > > > #### DEBUG TESTS ####
        > > >
        > > > mail_status "Test" "succes";
        > > >
        > > > ***CRONTAB LINE :
        > > >
        > > > 33 23 * * * /opt/bin/bash /temp/testmail/send_mail.sh
        > > >
        > >
        >
      • Marc Boris Dombrowa
        Most likely your environment is different than the one of the user running this cronjob Therefore add an env debug statement to the crontab. Check your path to
        Message 3 of 10 , Nov 22, 2009
        • 0 Attachment
          Most likely your environment is different than the one of the user
          running this cronjob
          Therefore add an env debug statement to the crontab. Check your path to
          the env binary.
          It is /usr/bin/env linked to opt/bin/env on my slug

          33 23 * * * /opt/bin/env > 1>/tmp/env.log 2>&1


          You will then use env in your shell and dump output again to a file
          env 1>~/env.log 2>&1

          then diff both files

          diff /tmp/env/log ~/env.log

          and you will see that e.g. your LD_LIBRARY_PATH and other settings differ.
          You need to adjust you settings either inside the crontab or source and
          environment inside cron prior to executing nail.

          Once done remove the env line in cron.

          Marc
        • Steve
          On my slugos 5.3 sendmail is in /usr/sbin. So try the following # find / -name sendmail -print if it show up in /usr/sbin/sendmail then do ln -s
          Message 4 of 10 , Nov 23, 2009
          • 0 Attachment
            On my slugos 5.3 sendmail is in /usr/sbin. So try the following

            # find / -name sendmail -print

            if it show up in /usr/sbin/sendmail then do
            ln -s /usr/sbin/sendmail /usr/lib/sendmail

            Replace /usr/sbin/sendmail with the path to the one you find. Then try again.

            /usr/lib/sendmail is a "well known" location for sendmail and it's common for even non-sendmail based mail systems put a fake one there so programs can find it.

            Steve

            --- In nslu2-linux@yahoogroups.com, "tkayna" <tkayna@...> wrote:
            >
            > Thanks,
            >
            > It returns me this :
            > $ cat /tmp/myLog.err
            > /usr/lib/sendmail: No such file or directory
            > . . . message not sent.
            >
            > And I have this in nail bin :
            > $strings /usr/bin/nail | grep sendmail
            > sendmail
            > /usr/lib/sendmail
            >
            > But I don't understand why it works in shell.
            >
            > Thank you for your help
            >
            > --- In nslu2-linux@yahoogroups.com, "rolandkbs" <roland.krebs@> wrote:
            > >
            > > I don't see the cause, but maybe I can help you to find it:
            > > Add to the end of your crontab line the following
            > > >/tmp/myLog.out 2>/tmp/myLog.err
            > >
            > > By inspecting the two files after the defined time has passed you will most probably find the problem.
            > >
            > > regards, Roland
            > >
            > > --- In nslu2-linux@yahoogroups.com, "tkayna" <tkayna@> wrote:
            > > >
            > > > Hello,
            > > >
            > > > I made un script to send mail.
            > > > My script works executing in shell but not in crontab.
            > > > I also add full path for binaries but it's the same.
            > > >
            > > > Can someone help me ?
            > > >
            > > > ***BASH SCRIPT send_mail.sh :
            > > >
            > > > #!/opt/bin/bash
            > > >
            > > > nail='/usr/bin/nail'
            > > > sleep='/bin/sleep'
            > > > echo='/bin/echo'
            > > >
            > > >
            > > > function mail_status ()
            > > > {
            > > > ${sleep} 1
            > > > ${echo} $1 $2 | ${nail} -s "save_sites_SQL_$1_$2" myemail@;
            > > > #echo $? > /tmp/testestest_sendmail.txt
            > > > }
            > > >
            > > > #### DEBUG TESTS ####
            > > >
            > > > mail_status "Test" "succes";
            > > >
            > > > ***CRONTAB LINE :
            > > >
            > > > 33 23 * * * /opt/bin/bash /temp/testmail/send_mail.sh
            > > >
            > >
            >
          • tkayna
            I don t have real differences between the two files, unless the PATH. But adding PATH to my script doesn t change anything. No LD_LIBRARY_PATH given in env.
            Message 5 of 10 , Nov 23, 2009
            • 0 Attachment
              I don't have real differences between the two files, unless the PATH.
              But adding PATH to my script doesn't change anything.
              No LD_LIBRARY_PATH given in env.

              --- In nslu2-linux@yahoogroups.com, Marc Boris Dombrowa <marbordom@...> wrote:
              >
              > Most likely your environment is different than the one of the user
              > running this cronjob
              > Therefore add an env debug statement to the crontab. Check your path to
              > the env binary.
              > It is /usr/bin/env linked to opt/bin/env on my slug
              >
              > 33 23 * * * /opt/bin/env > 1>/tmp/env.log 2>&1
              >
              >
              > You will then use env in your shell and dump output again to a file
              > env 1>~/env.log 2>&1
              >
              > then diff both files
              >
              > diff /tmp/env/log ~/env.log
              >
              > and you will see that e.g. your LD_LIBRARY_PATH and other settings differ.
              > You need to adjust you settings either inside the crontab or source and
              > environment inside cron prior to executing nail.
              >
              > Once done remove the env line in cron.
              >
              > Marc
              >
            • tkayna
              Thanks for your help. But I ve already search in this way. Sendmail is not installed on my OpenSlug. The command Find doesn t find anything. It was the reason
              Message 6 of 10 , Nov 23, 2009
              • 0 Attachment
                Thanks for your help.
                But I've already search in this way. Sendmail is not installed on my OpenSlug.
                The command Find doesn't find anything.
                It was the reason why I was surprise to see that nail looks for sendmail.

                --- In nslu2-linux@yahoogroups.com, "Steve" <stevebleazard@...> wrote:
                >
                > On my slugos 5.3 sendmail is in /usr/sbin. So try the following
                >
                > # find / -name sendmail -print
                >
                > if it show up in /usr/sbin/sendmail then do
                > ln -s /usr/sbin/sendmail /usr/lib/sendmail
                >
                > Replace /usr/sbin/sendmail with the path to the one you find. Then try again.
                >
                > /usr/lib/sendmail is a "well known" location for sendmail and it's common for even non-sendmail based mail systems put a fake one there so programs can find it.
                >
                > Steve
                >
                > --- In nslu2-linux@yahoogroups.com, "tkayna" <tkayna@> wrote:
                > >
                > > Thanks,
                > >
                > > It returns me this :
                > > $ cat /tmp/myLog.err
                > > /usr/lib/sendmail: No such file or directory
                > > . . . message not sent.
                > >
                > > And I have this in nail bin :
                > > $strings /usr/bin/nail | grep sendmail
                > > sendmail
                > > /usr/lib/sendmail
                > >
                > > But I don't understand why it works in shell.
                > >
                > > Thank you for your help
                > >
                > > --- In nslu2-linux@yahoogroups.com, "rolandkbs" <roland.krebs@> wrote:
                > > >
                > > > I don't see the cause, but maybe I can help you to find it:
                > > > Add to the end of your crontab line the following
                > > > >/tmp/myLog.out 2>/tmp/myLog.err
                > > >
                > > > By inspecting the two files after the defined time has passed you will most probably find the problem.
                > > >
                > > > regards, Roland
                > > >
                > > > --- In nslu2-linux@yahoogroups.com, "tkayna" <tkayna@> wrote:
                > > > >
                > > > > Hello,
                > > > >
                > > > > I made un script to send mail.
                > > > > My script works executing in shell but not in crontab.
                > > > > I also add full path for binaries but it's the same.
                > > > >
                > > > > Can someone help me ?
                > > > >
                > > > > ***BASH SCRIPT send_mail.sh :
                > > > >
                > > > > #!/opt/bin/bash
                > > > >
                > > > > nail='/usr/bin/nail'
                > > > > sleep='/bin/sleep'
                > > > > echo='/bin/echo'
                > > > >
                > > > >
                > > > > function mail_status ()
                > > > > {
                > > > > ${sleep} 1
                > > > > ${echo} $1 $2 | ${nail} -s "save_sites_SQL_$1_$2" myemail@;
                > > > > #echo $? > /tmp/testestest_sendmail.txt
                > > > > }
                > > > >
                > > > > #### DEBUG TESTS ####
                > > > >
                > > > > mail_status "Test" "succes";
                > > > >
                > > > > ***CRONTAB LINE :
                > > > >
                > > > > 33 23 * * * /opt/bin/bash /temp/testmail/send_mail.sh
                > > > >
                > > >
                > >
                >
              • tkayna
                I found a solution to bypass my problem thanks to tips of Marc and Roland. 1)My script worked in shell with user1 but not in crontab. 2)crontab is run by root.
                Message 7 of 10 , Nov 23, 2009
                • 0 Attachment
                  I found a solution to bypass my problem thanks to tips of Marc and Roland.
                  1)My script worked in shell with user1 but not in crontab.
                  2)crontab is run by root.
                  3)When I used "su -" and excute the script I have the same error as in crontab:
                  "
                  /usr/lib/sendmail: No such file or directory
                  . . . message not sent.
                  "
                  4)So I added "/bin/su user1 -c" to my script :
                  33 23 * * * /bin/su user1 -c '/opt/bin/bash /temp/testmail/send_mail.sh'

                  And this is OK now !

                  5)I choose that way because I've got a bad feeling that "nail" checks for the user (root or not root) and use sendmail !!!!

                  If someone understand what's happen, I am very interesting to know...

                  Thank You

                  T-Kayna

                  --- In nslu2-linux@yahoogroups.com, "tkayna" <tkayna@...> wrote:
                  >
                  > Hello,
                  >
                  > I made un script to send mail.
                  > My script works executing in shell but not in crontab.
                  > I also add full path for binaries but it's the same.
                  >
                  > Can someone help me ?
                  >
                  > ***BASH SCRIPT send_mail.sh :
                  >
                  > #!/opt/bin/bash
                  >
                  > nail='/usr/bin/nail'
                  > sleep='/bin/sleep'
                  > echo='/bin/echo'
                  >
                  >
                  > function mail_status ()
                  > {
                  > ${sleep} 1
                  > ${echo} $1 $2 | ${nail} -s "save_sites_SQL_$1_$2" myemail@...;
                  > #echo $? > /tmp/testestest_sendmail.txt
                  > }
                  >
                  > #### DEBUG TESTS ####
                  >
                  > mail_status "Test" "succes";
                  >
                  > ***CRONTAB LINE :
                  >
                  > 33 23 * * * /opt/bin/bash /temp/testmail/send_mail.sh
                  >
                • marbordom
                  The error message: /usr/lib/sendmail: No such file or directory points to a missing PATH to sendmail I believe this is what happens now causing your script
                  Message 8 of 10 , Nov 24, 2009
                  • 0 Attachment
                    The error message: "/usr/lib/sendmail: No such file or directory" points to a missing PATH to sendmail

                    I believe this is what happens now causing your script to run successfully. Your command:
                    /bin/su user1 -c '/opt/bin/bash /temp/testmail/send_mail.sh'
                    causes user1 to use /opt/bin/bash as a shell.
                    If you have e.g. a .bash_profile in user1's $HOME this profile will be sourced setting PATH variable and all the environment you have when you log in as user1. This makes the shell and the cron environment match and e.g. PATH will be set correctly.

                    I bet that you could run this as root as well if you source root's profile prior to the command, like adding:

                    . ~/.bash_profile or
                    . ~/.profile (depends on which shell your root has) to your
                    script: /temp/testmail/send_mail.sh

                    and then edit crontab to:

                    33 23 * * * /temp/testmail/send_mail.sh

                    if user1's shell is /opt/bin/bash anyway, this [c|sh]ould work as well - no su required:

                    33 23 * * * user1 /temp/testmail/send_mail.sh

                    Marc

                    --- In nslu2-linux@yahoogroups.com, "tkayna" <tkayna@...> wrote:

                    > 4)So I added "/bin/su user1 -c" to my script :
                    > 33 23 * * * /bin/su user1 -c '/opt/bin/bash /temp/testmail/send_mail.sh'
                    >
                    > And this is OK now !
                    >
                  Your message has been successfully submitted and would be delivered to recipients shortly.