You are not logged in.

#1 2005-07-29 05:38:30

FJ
Member
From: Ontario, Canada
Registered: 2005-03-17
Posts: 75
Website

How to NOT log certain cronjobs

I have a job that runs once a minute, and it logs the event to /var/log/crond.  This makes for huge and boring log files.  Is there a way to turn off logging for just this job?  Is there an option I can set in my crontab?

Offline

#2 2005-07-29 16:46:47

dk
Member
Registered: 2004-04-20
Posts: 106

Re: How to NOT log certain cronjobs

> /dev/null 2>&1

Offline

#3 2005-07-29 23:43:23

FJ
Member
From: Ontario, Canada
Registered: 2005-03-17
Posts: 75
Website

Re: How to NOT log certain cronjobs

Thanks..

Could you perhaps elaborate a bit on that?  I'm not sure where to put that piece of code.  My crontab entry is as follows

* * * * * if [ -x /usr/bin/vnstat ] && [ `ls /var/lib/vnstat/ | wc -l` -ge 1 ]; then /usr/bin/vnstat -u; fi

I tried putting it after the if statement and so that led to failure.  I put it after the called vnstat command after the then and it logged it anyway.  Yeah, as you can tell I'm still new at this wink

Offline

#4 2005-07-29 23:53:43

jackmetal
Member
From: US
Registered: 2005-06-13
Posts: 164

Re: How to NOT log certain cronjobs

Try:

* * * * * if [ -x /usr/bin/vnstat ] && [ `ls /var/lib/vnstat/ | wc -l` -ge 1 ]; then /usr/bin/vnstat -u >> /dev/null 2>&1; fi

and see if that works..

Hope that helps!


--

Some of the world's greatest feats were
accomplished by people not smart enough
to know they were impossible.
-- Doug Larson

Offline

#5 2005-07-30 00:51:58

FJ
Member
From: Ontario, Canada
Registered: 2005-03-17
Posts: 75
Website

Re: How to NOT log certain cronjobs

fullmetaljack: Well, it didn't return an error, but I get this in the crond log file now:

29-Jul-2005 20:49  USER root pid 6727 cmd if [ -x /usr/bin/vnstat ] && [ `ls /var/lib/vnstat/ | wc -l` -ge 1 ]; then /usr/bin/vnstat -u >> /dev/null 2>&1; fi

In other words, it still reports the event.  Perhaps the crontab isn't the place to change this, but then where I wonder?  I suppose I could try and write a script that looks for this line in /var/log/crond, and if it finds it, it replaces it with a blank line and moves one line up.

Offline

#6 2005-07-30 12:48:25

jackmetal
Member
From: US
Registered: 2005-06-13
Posts: 164

Re: How to NOT log certain cronjobs

I'm sorry FJ,  I mis-read your post.  I just re-read it and I see what you're trying to do.  The command I gave you will send all output from 'the command ran' to /dev/null, not the actual 'cron log' of running the command.   

Hmmmmm. 

The cron logging is specifically setup in /etc/rc.d/crond to log any job kicked off by cron into /var/log/crond. 

If you don't want the command to log at all, the only thing I can think of is for you to run it as a small looping script that will sleep for 60 seconds and then run the command again.  The script could be called in /etc/rc.local, and it will run at every system startup.

Basically just create a little script that will run your command (you can use the ">> /dev/nul 2>&1" after it to send all output from it to dev/null), then have it "sleep 60", then loop back and run your command again.   That should accomplish what you're wanting.

All cron jobs will log when they run, I can't think of a way to have a specific cron job "not" log..........unless..........You wrote a wrapper for crond that could use a conf file similar to the way syslog uses syslog-ng.conf (/etc/syslog-ng/syslog-ng.conf)...


--

Some of the world's greatest feats were
accomplished by people not smart enough
to know they were impossible.
-- Doug Larson

Offline

#7 2005-07-31 06:01:16

FJ
Member
From: Ontario, Canada
Registered: 2005-03-17
Posts: 75
Website

Re: How to NOT log certain cronjobs

I took your advice. I wrote this script

#!/bin/bash
#Name: vnstat-60sec

while [ 0 -le 1 ] #while 0<=1, in other words forever.
do
if [ -x /usr/bin/vnstat ] && [ `ls /var/lib/vnstat/ | wc -l` -ge 1 ]; then /usr/bin/vnstat -u; fi
sleep 60
done

I then put into /etc/rc.local

/usr/bin/vnstat-60sec &

I'd love to write a wrapper to crond, but that is way beyond my skills!  Cheers.

Offline

#8 2005-08-02 04:04:35

FJ
Member
From: Ontario, Canada
Registered: 2005-03-17
Posts: 75
Website

Re: How to NOT log certain cronjobs

I have an update.  I was playing around with KCron for KDE and it has a "silent" option which overrides logging.  It uses crond and what it does is put a hyphen (-) in front of the crontab entry.  But /var/log/crond logged a complaint saying the entry couldn't be parsed and the event ended up not running (but it didn't log failure either).

So it seems that theoretically it's possible to not log cronjobs, but for some reason my crond doesn't like the hyphen-format.  All very interesting.

Offline

#9 2005-08-02 07:36:27

IceRAM
Member
From: Bucharest, Romania
Registered: 2004-03-04
Posts: 772
Website

Re: How to NOT log certain cronjobs

Maybe it works with other cron daemons.
I'm starting to think that some other "more not strictly time dependant" crons are more appropriate for desktop usage.

Offline

#10 2005-08-02 15:50:23

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: How to NOT log certain cronjobs

You can try anacron. I've submitted it to the AUR. My anacron log is empty. I *think* that it only reports cron jobs errors.

Offline

#11 2005-08-03 01:54:21

FJ
Member
From: Ontario, Canada
Registered: 2005-03-17
Posts: 75
Website

Re: How to NOT log certain cronjobs

Snowman, thanks for the info.  Anacron looks pretty useful for desktop users, and I may pick it up, but unfortunately it doesn't seem to solve my current problem.  However it's very nice for when I interrupt my uptime with a shutdown/reboot.

It mentions that

Anacron is not an attempt to make cron redundant. It cannot be used to schedule commands at intervals smaller than days. It also does not guarantee that the commands will be executed at any specific day or hour.

It isn't a full-time daemon. It has to be executed from boot scripts, from cron-jobs, or explicitly.

Offline

#12 2005-08-03 04:30:30

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: How to NOT log certain cronjobs

Sorry about that... I forgot that the smallest interval was a day. :oops:

Offline

#13 2005-08-03 07:00:44

juergen
Developer
From: Frankfurt/Germany
Registered: 2005-04-11
Posts: 48
Website

Re: How to NOT log certain cronjobs

Using syslog-ng any you can filter everything by regular expressions.

Offline

#14 2005-08-03 07:15:23

IceRAM
Member
From: Bucharest, Romania
Registered: 2004-03-04
Posts: 772
Website

Re: How to NOT log certain cronjobs

I've also heard of vixie cron, which seems to be replaced in AUR by a more powerful app: fcron
Here is the description: http://fcron.free.fr/description.php

Indeed, I filter the undeeded log entries with the filters in syslog-ng.

Offline

#15 2005-08-07 18:58:06

FJ
Member
From: Ontario, Canada
Registered: 2005-03-17
Posts: 75
Website

Re: How to NOT log certain cronjobs

I will work on figuring out syslog-ng.  In the meantime I've just written

sed -i '/vnstat/d' /var/log/crond

Thanks for all the help.

Offline

#16 2005-08-07 22:06:30

FJ
Member
From: Ontario, Canada
Registered: 2005-03-17
Posts: 75
Website

Re: How to NOT log certain cronjobs

Actually I recommend not trying what I just did.  Apparently after running this in my crontab, crond stopped all logging!  Restarting the daemon fixed it.

Offline

Board footer

Powered by FluxBB