Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Mar 2004
    Posts
    859

    Default Shell script will not run via cron?

    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. #2
    Member
    Join Date
    Mar 2004
    Posts
    859

    Default

    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. #3
    Member brianoz's Avatar
    Join Date
    Mar 2004
    Location
    Melbourne, Australia
    Posts
    1,117
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    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. #4
    Member
    Join Date
    Mar 2004
    Posts
    859

    Default

    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. #5
    Member brianoz's Avatar
    Join Date
    Mar 2004
    Location
    Melbourne, Australia
    Posts
    1,117
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    yes, it's in the home directory of the user running the crontab file.

Similar Threads & Tags
Similar threads

  1. Cron Job, Run PHP script
    By bowers01 in forum New User Questions
    Replies: 2
    Last Post: 11-18-2010, 03:23 PM
  2. Replies: 3
    Last Post: 03-29-2007, 04:31 AM
  3. 500 error after ZendOpt update script run from shell
    By agentseven in forum cPanel and WHM Discussions
    Replies: 6
    Last Post: 05-30-2005, 11:05 PM
  4. Replies: 1
    Last Post: 05-18-2003, 09:46 AM
  5. Script wont run in cron
    By Aerosmith in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 05-05-2002, 07:40 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube