You are not logged in.
Pages: 1
Topic closed
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
> /dev/null 2>&1
Offline
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; fiI 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 ![]()
Offline
Try:
* * * * * if [ -x /usr/bin/vnstat ] && [ `ls /var/lib/vnstat/ | wc -l` -ge 1 ]; then /usr/bin/vnstat -u >> /dev/null 2>&1; fiand 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
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; fiIn 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
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
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
doneI 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
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
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.
:: / my web presence
Offline
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
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
Sorry about that... I forgot that the smallest interval was a day. :oops:
Offline
Using syslog-ng any you can filter everything by regular expressions.
Offline
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.
:: / my web presence
Offline
I will work on figuring out syslog-ng. In the meantime I've just written
sed -i '/vnstat/d' /var/log/crondThanks for all the help.
Offline
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
I made something similar in Debian with Rsyslog to ignore from the syslog the entries for cron jobs for an specific user ("jhablutzel"). I just created /etc/rsyslog.d/99-ignore-cron-jobs-for-jhablutzel.conf:
if $programname == 'CRON' and $msg contains '(jhablutzel) CMD (' then {
stop
}
Offline
I don't understand why you felt the need to ressurect an 18 year old topic to tell people about what you've done on another distro. Don't do that.
https://wiki.archlinux.org/title/Genera … bumping%22
Closing.
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Pages: 1
Topic closed