Results 1 to 8 of 8

Thread: openSuse, not running the cron job

  1. #1

    Default openSuse, not running the cron job

    I have created a cron job in the /etc/cron.d/dispatchingEmail_I

    content of the dispatchingEmail_I is:
    Code:
    54 19 * * * root /home/harbir/project/L_ocalRepository/smallworks/maildispatcher.sh >> /tmp/try1.log
    The permissions of the above cron file are the following:

    Code:
    -rw-r--r--   1 root root    84 Sep 11 19:52 dispatchingEmail_I
    when I check /var/log/messages I can see an entry

    Code:
    2014-09-11T19:54:01.761269+10:00 linux-gn77-PC /USR/SBIN/CRON[4109]: (root) CMD (/home/harbir/project/L_ocalRepository/smallworks/maildispatcher.sh)
    which tells me that the command has run, but no email has been received. The log file gets created, but its empty.
    where as when I run the script by itself, the email is received.
    the permissions of the file maildispatcher.sh are the following:
    Code:
    -rwxrwx---  1 harbir users      621 Sep 10 06:33 maildispatcher.sh
    The two reasons that tell me that my script is not getting run via cron job are:
    1. log is empty
    2. script fires up a java program that updates a file before sending an email. The file is not getting updated.

    when I run a simple command like
    Code:
    50 05 * * * root echo checking >>/tmp/try2.log
    the cronjob works and has contents in the log file.
    can anyone suggest some changes that can be tried?

  2. #2
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    12,180
    Blog Entries
    3

    Default Re: openSuse, not running the cron job

    As far as I know, a cron job has to be an executable program.

    To use a shell script, make the command: bash -c /path/to/script

    Alternatively, give it "x" permissions and make sure that the first line begin something like "#! /bin/bash -"
    openSUSE Leap 15.1; KDE Plasma 5;

  3. #3

    Default Re: openSuse, not running the cron job

    Quote Originally Posted by nrickert View Post
    As far as I know, a cron job has to be an executable program.

    To use a shell script, make the command: bash -c /path/to/script

    Alternatively, give it "x" permissions and make sure that the first line begin something like "#! /bin/bash -"
    https://en.opensuse.org/SDB:Cron

    under section /etc/cron.d

    "This is the good place when you want to create cron job rule for your package and you want exact date/time of execution. Your crontab rule could be normal file,symlink or hardlink. It have to be owned by root (also write allowed only for root) and not executable. "

  4. #4
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    12,180
    Blog Entries
    3

    Default Re: openSuse, not running the cron job

    Quote Originally Posted by harbir_linuxuser View Post
    "This is the good place when you want to create cron job rule for your package and you want exact date/time of execution. Your crontab rule could be normal file,symlink or hardlink. It have to be owned by root (also write allowed only for root) and not executable. "
    I think you may have misunderstood that.

    It is talking about the file containing the rule. It is not talking about the shell script command file that is invoked by the rule.
    openSUSE Leap 15.1; KDE Plasma 5;

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,729

    Default Re: openSuse, not running the cron job

    Quote Originally Posted by harbir_linuxuser View Post
    https://en.opensuse.org/SDB:Cron

    under section /etc/cron.d

    "This is the good place when you want to create cron job rule for your package and you want exact date/time of execution. Your crontab rule could be normal file,symlink or hardlink. It have to be owned by root (also write allowed only for root) and not executable. "
    That is about the the defenition file in the /etc/cron.d directory and not about the file/command you want to execute.

    The file you want to execute, must be executable (surprise) for the user executing it. In short, when the owner is root, the x-bit must be set for the owner of the file.
    And when the file is a scipt, do not forget the shebang (e.g.
    Code:
    #!/bin/bash)
    as the first line of the script.
    Henk van Velden

  6. #6
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: openSuse, not running the cron job

    On 2014-09-11 22:26, harbir linuxuser wrote:
    >
    > I have created a cron job in the
    > /etc/cron.d/dispatchingEmail_I
    >
    >
    >
    >
    > content of the dispatchingEmail_I is:
    >
    > Code:
    > --------------------
    > 54 19 * * * root /home/harbir/project/L_ocalRepository/smallworks/maildispatcher.sh >> /tmp/try1.log
    > --------------------


    If it is going to run as root, why is the script hosted by user
    "harbir"? It should be in "/root/bin/", or maybe "/usr/local/bin/".


    > The permissions of the above cron file are the following:
    >
    >
    > Code:
    > --------------------
    > -rw-r--r-- 1 root root 84 Sep 11 19:52 dispatchingEmail_I
    > --------------------


    Ok.

    > when I check /var/log/messages I can see an entry
    >
    >
    > Code:
    > --------------------
    > 2014-09-11T19:54:01.761269+10:00 linux-gn77-PC /USR/SBIN/CRON[4109]: (root) CMD (/home/harbir/project/L_ocalRepository/smallworks/maildispatcher.sh)
    > --------------------


    Ok.

    > which tells me that the command has run, but no email has been received.


    Email? What email? :-??


    Your dispatchingEmail_I should be like this:

    Code:
    SHELL=/bin/bash
    MAILTO="harbir"
    
    54 19 * * * root /root/bin/project/maildispatcher.sh

    And then, examine _local_ system email to "harbir" to find out what
    happened.





    > 2. script fires up a java program that


    Does it need to use the display at all? Then it will fail.



    --
    Cheers / Saludos,

    Carlos E. R.
    (from 13.1 x86_64 "Bottle" at Telcontar)

  7. #7
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: openSuse, not running the cron job

    On 2014-09-11 23:26, hcvv wrote:

    >
    > The file you want to execute, must be executable (surprise) for the user
    > executing it. In short, when the owner is root, the x-bit must be set
    > for the owner of the file.


    Looking at his post, it is executable by the owner:

    > Code:
    > --------------------
    > -rwxrwx--- 1 harbir users 621 Sep 10 06:33 maildispatcher.sh
    > --------------------


    but the cron job calls the script as root, so I guess it will not run.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 13.1 x86_64 "Bottle" at Telcontar)

  8. #8

    Default Re: openSuse, not running the cron job

    Hi all, I have found the issue, its nothing to with the cron job. The script file that I was trying run was refering to the wrong class path, and hence the java program was not running, I will do extra checking next time. Thank you all for helping.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •