Noob Cronjob question

pixel_ninja

Expert Member
Joined
May 21, 2010
Messages
1,215
Reaction score
4
Location
Aokautere
HI Guys,

I have configured a shell command file which dumps a list of banned websites into the bannedsitelist, and a second shell which clears the contents of that list.

Now all I have to do is schedule a cron job to run the enable.sh/disable.sh shell commands. here are the steps I followed:

cd /root

nano WEBFILTER

0 8 * * 1,2,3,4,5 /root/enable.sh >/dev/null 2>&1
0 10 * * 1,2,3,4,5 /root/disable.sh >/dev/null 2>&1
15 10 * * 1,2,3,4,5 /root/enable.sh >/dev/null 2>&1
0 13 * * 1,2,3,4,5 /root/disable.sh >/dev/null 2>&1
0 14 * * 1,2,3,4,5 /root/enable.sh >/dev/null 2>&1
30 16 * * 1,2,3,4,5 /root/disable.sh >/dev/null 2>&1

crontab WEBFILTER

I have manually run the enable.sh/disable.sh and it does block/unblock the sites, so I suspect that I have not configured the cron correctly.

Any advice would be great :)
 
To see if it installed correctly do

contab -l

Remember that the when the cronjob runs it does not have all the paths setup (as when you log in with the user)
Dump the job output to a file that you can review.

btw the 1,2,3,4,5 can be written as 1-5
 
Last edited:
HI Guys,

I have configured a shell command file which dumps a list of banned websites into the bannedsitelist, and a second shell which clears the contents of that list.

Now all I have to do is schedule a cron job to run the enable.sh/disable.sh shell commands. here are the steps I followed:

cd /root

nano WEBFILTER

0 8 * * 1,2,3,4,5 /root/enable.sh >/dev/null 2>&1
0 10 * * 1,2,3,4,5 /root/disable.sh >/dev/null 2>&1
15 10 * * 1,2,3,4,5 /root/enable.sh >/dev/null 2>&1
0 13 * * 1,2,3,4,5 /root/disable.sh >/dev/null 2>&1
0 14 * * 1,2,3,4,5 /root/enable.sh >/dev/null 2>&1
30 16 * * 1,2,3,4,5 /root/disable.sh >/dev/null 2>&1

crontab WEBFILTER

I have manually run the enable.sh/disable.sh and it does block/unblock the sites, so I suspect that I have not configured the cron correctly.

Any advice would be great :)

Can you post the content of one of the enable/disable .sh files? I suspect you may have neglected to use absolute pathing for the commands, which is required for cron, since it would not use your default shell.

For example 'ifconf' would need to be '/sbin/ifconf'
 
To see if it installed correctly do

contab -l

Remember that the when the cronjob runs it does not have all the paths setup (as when you log in with the user)
Dump the job output to a file that you can review.

I have run it and it looks fine, as well as crontab -e

Can you post the content of one of the enable/disable .sh files? I suspect you may have neglected to use absolute pathing for the commands, which is required for cron, since it would not use your default shell.

For example 'ifconf' would need to be '/sbin/ifconf'

service dansguardian-av stop
yes | cp -rf /etc/dansguardian-av/lists/onbannedsitelist /etc/dansguardian-av/lists/bannedsitelist
service dansguardian-av start
 
I have run it and it looks fine, as well as crontab -e
service dansguardian-av stop
yes | cp -rf /etc/dansguardian-av/lists/onbannedsitelist /etc/dansguardian-av/lists/bannedsitelist
service dansguardian-av start

paths is your problem.

either
do the following

PATH=$PATH:/sbin:/usr/bin:/bin
service dansguardian-av stop
yes | cp -rf /etc/dansguardian-av/lists/onbannedsitelist /etc/dansguardian-av/lists/bannedsitelist
service dansguardian-av start

or put the path to the command in the script
/sbin/service dansguardian-av stop
etc

on my machine it is /bin,/sbin and /usr/bin
locate it by doing
which service
which yes
which cp
 
paths is your problem.

either
do the following

PATH=$PATH:/sbin:/usr/bin:/bin
service dansguardian-av stop
yes | cp -rf /etc/dansguardian-av/lists/onbannedsitelist /etc/dansguardian-av/lists/bannedsitelist
service dansguardian-av start

or put the path to the command in the script
/sbin/service dansguardian-av stop
etc

on my machine it is /bin,/sbin and /usr/bin
locate it by doing
which service
which yes
which cp

Was about to post this ^

This should solve your problem, let us know :)
 
paths is your problem.

either
do the following

PATH=$PATH:/sbin:/usr/bin:/bin
service dansguardian-av stop
yes | cp -rf /etc/dansguardian-av/lists/onbannedsitelist /etc/dansguardian-av/lists/bannedsitelist
service dansguardian-av start

or put the path to the command in the script
/sbin/service dansguardian-av stop
etc

on my machine it is /bin,/sbin and /usr/bin
locate it by doing
which service
which yes
which cp

I've tried changing it to both options, then just created another line in the crontab to test but it still doesnt seem to run the enable.sh
 
Just asking but are all your permissions correct ?

This is a clean install of Clearos 6.4, it does everything that I need it to, but it cannot seem to filter by time, which is why i have to dive under the hood. so I'm not sure if that is the problem?

nano /temp.debug.log

is that the correct way of viewing the log file? when I type that in it is blank. Same with the cron.allow/deny

Sorry for my stupidity :P
 
Last edited:
nano /temp.debug.log

is that the correct way of viewing the log file? when I type that in it is blank. Same with the cron.allow/deny

Not the correct way

Correct way
nano /tmp/debug.log

or
cat /tmp/debug.log

cat /etc/cron.deny

cat /etc/cron.allow
 
what size is /temp.debug.log ?
If it is 0 then nothing is pumped into which probably means no error is being displayed ...
Have you checked the crontab logs or system logs for errors ?
 
post the following output
tail -50 /var/log/cron

wait a bit ... 'none have text'
please post what the output is of
ls -la /etc/cron.allow
 
Last edited:
I just want to confirm the enable.sh with you guys again:

/sbin/service dansguardian-av stop
/usr/bin/yes | /bin/cp -rf /etc/dansguardian-av/lists/onbannedsitelist /etc/dansguardian-av/lists/bannedsitelist
/sbin/service dansguardian-av start

it runs when I run:

bash enable.sh

I've tried putting echo on just to see what would happen:

30 12 * * 1,2,3,4,5 /root/enable.sh >/dev/null 2>&1 Echo "test"

but it doesnt display anything at 12:30 (or block the sites by running the enable.sh)
 
Last edited:
May 15 12:41:01 OHS CROND[9489]: (root) CMD (/root/enable.sh >/debug.log 2>&1)
May 15 12:42:01 OHS CROND[9493]: (root) CMD (/root/enable.sh >/debug.log 2>&1)
 
Last edited:
ok! success! well, sort of, the log says that its a permission error ( as DGremlin eluded to earlier)
 
How did you then test it from the command line ?
 
How did you then test it from the command line ?

well I ran

bash enable.sh

I saw it stopping DG, restart it, and I tested it by trying to browse a banned site, which then blocked me. but when crontab runs the enable.sh I get the permission error when running the

tail -50 /var/log/cron
 
Top
Sign up to the MyBroadband newsletter
X