Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
Hi All, I have script which runs ok but if I call it from crontab it does not run. In /var/logs/cron log i can see after every min crontab calls ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    16

    sh script does not execute if called by cronjob


    Hi All,

    I have script which runs ok but if I call it from crontab it does not run. In /var/logs/cron log i can see after every min crontab calls the script. I have added path variable,

    # File: delete_archivelog.sh
    #!/bin/bsh
    # ----------------------------------
    export ORACLE_HOME=/home/oracle/john/oracle/product/11.2.0/db_1
    export ORACLE_SID=TestDB
    PATH=/home/oracle/john/oracle/product/11.2.0/db_1/bin:/usr/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin
    rman log=delete_archive.log <<EOF
    connect target sys/B4cKD00r
    connect catalog rman/3B45UGH
    run { execute script delete_archivelog;}
    exit;
    EOF
    #

    Above script runs in terminal

    I am calling this script from crontab

    */1 * * * * /home/oracle/scripts/delete_archivelog.sh

    this is entry in crontab

    I can see in logs that every min its being called by crontab
    May 18 20:27:01 ora11-nab-dr1 crond[9290]: (oracle) CMD (/home/oracle/scripts/delete_archivelog.sh)
    May 18 20:28:01 ora11-nab-dr1 crond[9351]: (oracle) CMD (/home/oracle/scripts/delete_archivelog.sh)
    May 18 20:29:01 ora11-nab-dr1 crond[9385]: (oracle) CMD (/home/oracle/scripts/delete_archivelog.sh)
    May 18 20:30:01 ora11-nab-dr1 crond[9443]: (root) CMD (/usr/lib64/sa/sa1 1 1)
    May 18 20:30:01 ora11-nab-dr1 crond[9444]: (oracle) CMD (/home/oracle/scripts/delete_archivelog.sh)
    May 18 20:31:01 ora11-nab-dr1 crond[9510]: (oracle) CMD (/home/oracle/scripts/delete_archivelog.sh)

    Any ideas/suggestions?

    Many thanks in advance

  2. #2
    Linux Newbie
    Join Date
    Apr 2012
    Posts
    112
    Quote Originally Posted by newchaptolinux View Post
    Hi All,

    I have script which runs ok but if I call it from crontab it does not run. In /var/logs/cron log i can see after every min crontab calls the script. I have added path variable,

    # File: delete_archivelog.sh
    #!/bin/bsh
    # ----------------------------------
    export ORACLE_HOME=/home/oracle/john/oracle/product/11.2.0/db_1
    export ORACLE_SID=TestDB
    PATH=/home/oracle/john/oracle/product/11.2.0/db_1/bin:/usr/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin
    rman log=delete_archive.log <<EOF
    connect target sys/B4cKD00r
    connect catalog rman/3B45UGH
    run { execute script delete_archivelog;}
    exit;
    EOF
    #

    Above script runs in terminal

    I am calling this script from crontab

    */1 * * * * /home/oracle/scripts/delete_archivelog.sh

    this is entry in crontab

    I can see in logs that every min its being called by crontab
    May 18 20:27:01 ora11-nab-dr1 crond[9290]: (oracle) CMD (/home/oracle/scripts/delete_archivelog.sh)
    May 18 20:28:01 ora11-nab-dr1 crond[9351]: (oracle) CMD (/home/oracle/scripts/delete_archivelog.sh)
    May 18 20:29:01 ora11-nab-dr1 crond[9385]: (oracle) CMD (/home/oracle/scripts/delete_archivelog.sh)
    May 18 20:30:01 ora11-nab-dr1 crond[9443]: (root) CMD (/usr/lib64/sa/sa1 1 1)
    May 18 20:30:01 ora11-nab-dr1 crond[9444]: (oracle) CMD (/home/oracle/scripts/delete_archivelog.sh)
    May 18 20:31:01 ora11-nab-dr1 crond[9510]: (oracle) CMD (/home/oracle/scripts/delete_archivelog.sh)

    Any ideas/suggestions?

    Many thanks in advance
    Not sure that this is the cause but you mistyped the shebang line

    Code:
    #!/bin/bsh

  3. #3
    Just Joined!
    Join Date
    Dec 2010
    Posts
    16
    Quote Originally Posted by manyrootsofallevil View Post
    Not sure that this is the cause but you mistyped the shebang line

    Code:
    #!/bin/bsh
    I have edited the line to #!/bin/sh

    yeah and its not cause still not working

  4. #4
    Just Joined!
    Join Date
    Jul 2011
    Location
    Monticello, Florida
    Posts
    1

    Environment

    Quote Originally Posted by newchaptolinux View Post
    I have edited the line to #!/bin/sh

    yeah and its not cause still not working
    The crontab runs with a very limited set of enviroment variables. Anything your script assumes from the environment should be fully specified so as not to rely on any nev variables.

  5. #5
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    664
    Oracle stuff requires so many environment tweaks that, rather than find them all and set them up in a cron script, I tend to put oracle cron jobs in a root crontab context and run them with "su - oracle -c path-to-script".

    That way it runs in an oracle login shell, which should have the same environment as your command line login shell.

  6. #6
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    648
    The "#!/bin/bash" line MUST BE the FIRST line in the file otherwise "/bin/sh" is used to run the command.

  7. #7
    Just Joined!
    Join Date
    Mar 2009
    Location
    Santa Cruz, California
    Posts
    76
    Actually I think what was meant originally for the 'shebang' was

    #!/bin/bash

    even when bash and sh are the same file, they do not necessarily behave the same - the program can look at the first token in the command line to determine how the program was evoked. For example, in a script, you can use

    $(basename $0)

    to see the name the script was evoked with (e.g. a symlink or and alias for the script name).

  8. #8
    Just Joined!
    Join Date
    Mar 2009
    Location
    Santa Cruz, California
    Posts
    76
    Here is a C program which displays the name with which it was evoked, followed by any command line parameters:

    /* foo.c
    This program prints the command name by which it was evoked,
    followed by its command-line parameters.
    */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <errno.h>

    # this is needed for the basename() function.
    #include <libgen.h>

    int main( int argc, char **argv)
    {
    int ii;
    printf( "argc = %d\n", argc );
    /* print command name */
    printf( "%s ", basename( argv[0] ) );
    /* print parameters */
    for ( ii = 1; ii < argc; ii++ )
    printf( "%s ", argv[ii] );
    printf("\n");
    }

    If the compiled object file is 'foo', create symlink: ln -s foo bah
    and then try

    foo a b c
    bah a b c

  9. #9
    Just Joined!
    Join Date
    Mar 2009
    Location
    Santa Cruz, California
    Posts
    76
    Quote Originally Posted by velikij View Post
    Actually I think what was meant originally for the 'shebang' was

    #!/bin/bash

    even when bash and sh are the same file, they do not necessarily behave the same - the program can look at the first token in the command line to determine how the program was evoked. For example, in a script, you can use

    $(basename $0)

    to see the name the script was evoked with (e.g. a symlink or and alias for the script name).

    Actually this script may work differently on non-Debian-based systems. I've only tried basename on Debian and Ubuntu.

  10. #10
    Just Joined!
    Join Date
    Dec 2010
    Posts
    13
    Hi,
    This problem once happened to me. What I did is instead of running the script every 1 min from crontob, I changed the time and started running the script every 10 min.
    I think the problem is every 1 min a new process start but before it finishes another process starts.


    --Regards,
    Sumit.

Page 1 of 2 1 2 LastLast

Posting Permissions

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