The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Shell script will not run via cron?

Discussion in 'General Discussion' started by jols, Nov 20, 2006.

  1. jols

    jols Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,111
    Likes Received:
    2
    Trophy Points:
    38
    Here's the entre script, runs find from the command line:

    #!/bin/bash
    for i in `tail -100 /usr/local/apache/logs/access_log | awk '/408/ {print $1}'|sort`
    do
    x=`grep -c $i /usr/local/apache/logs/access_log`
    if [ $x -gt 5 ]
    then
    csf -d $i 408 errors - $x -
    fi
    done


    But it does not run via cron, here's what I have tried:

    crontab -e

    Then at the bottom, I insert this:

    * * * * * /root/z408.sh


    And again, entering the following via shell runs the script fine:

    /root/z408.sh

    So what could this be?
     
  2. jols

    jols Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,111
    Likes Received:
    2
    Trophy Points:
    38
    No errors in the /var/log/cron just this:

    Nov 20 06:54:01 skyline crond[26190]: (root) CMD (/root/z408.sh)

    So everything looks like it should run, and it does manually, just not from the cron.


    I just had it set to run every minute while testing.


    When you say, "..and check the "logfile" file in your home directory after it runs." I gues that would just be in the server /root dir?

    Thanks for you help.
     
  3. brianoz

    brianoz Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,146
    Likes Received:
    6
    Trophy Points:
    38
    Location:
    Melbourne, Australia
    cPanel Access Level:
    Root Administrator
    are there any errors in your cron log?

    You could try redirecting stderr into a file (by default in the account home directory), ie:

    Code:
    * * * * * /root/z408.sh > logfile 2>&1
    and check the "logfile" file in your home directory after it runs.

    BTW do you really want to run this every minute? That's a fair load on the server potentially!
     
  4. jols

    jols Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,111
    Likes Received:
    2
    Trophy Points:
    38
    Okay, that really helped. I saw from looking at the logfile that I failed to put in an absolute path to the csf program. Now it is working, I think.

    Thanks very much!
     
  5. brianoz

    brianoz Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,146
    Likes Received:
    6
    Trophy Points:
    38
    Location:
    Melbourne, Australia
    cPanel Access Level:
    Root Administrator
    yes, it's in the home directory of the user running the crontab file.
     
Loading...

Share This Page