Shell script will not run via cron?

jols

Well-Known Member
Mar 13, 2004
1,110
3
168
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?
 

jols

Well-Known Member
Mar 13, 2004
1,110
3
168
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.
 

brianoz

Well-Known Member
Mar 13, 2004
1,146
7
168
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!
 

jols

Well-Known Member
Mar 13, 2004
1,110
3
168
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!