View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 12 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Sat Mar 17, 2007 7:16 pm 
Offline
Joined: Tue Aug 16, 2005 11:50 am
Posts: 181
Location: Douglasville, GA
I've use cron jobs to do things on my unix servers for 8 years now. I've never really known too much about cron... I didn't need to. Cron just works. Well, it does on every box, but my MythTV box.

Between cron and anacron, I am confused. I don't have the time to learn this. I'm trying the learn to do a linux-ha heartbeat MySQL array for work, and I'm trying to learn to program in Mono in my free time.

my syslogs look like this:
Code:
Mar 17 06:25:01 mythtv /USR/SBIN/CRON[4616]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))
Mar 17 06:25:01 mythtv /USR/SBIN/CRON[4617]: (root) CMD ([ -x /usr/lib/sysstat/sa1 ] && { [ -r "$DEFAULT" ] && . "$DEFAULT" ; [ "$ENABLED" = "true
" ] && exec /usr/lib/sysstat/sa1 $SA1_OPTIONS 1 1 ; })
Mar 17 06:30:01 mythtv /USR/SBIN/CRON[4658]: (root) CMD (test -x /usr/local/bin/run_rrd && /usr/local/bin/run_rrd)
Mar 17 06:35:01 mythtv /USR/SBIN/CRON[4699]: (root) CMD (test -x /usr/local/bin/run_rrd && /usr/local/bin/run_rrd)
Mar 17 06:35:01 mythtv /USR/SBIN/CRON[4700]: (root) CMD ([ -x /usr/lib/sysstat/sa1 ] && { [ -r "$DEFAULT" ] && . "$DEFAULT" ; [ "$ENABLED" = "true
" ] && exec /usr/lib/sysstat/sa1 $SA1_OPTIONS 1 1 ; })

...
Mar 17 07:30:01 mythtv /USR/SBIN/CRON[5259]: (root) CMD (test -x /usr/local/bin/run_rrd && /usr/local/bin/run_rrd)
Mar 17 07:30:01 mythtv /USR/SBIN/CRON[5260]: (root) CMD (test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null)
Mar 17 07:30:01 mythtv anacron[5281]: Anacron 2.3 started on 2007-03-17
Mar 17 07:30:01 mythtv anacron[5281]: Will run job `cron.daily' in 5 min.
Mar 17 07:30:01 mythtv anacron[5281]: Jobs will be executed sequentially
Mar 17 07:35:01 mythtv /USR/SBIN/CRON[5321]: (root) CMD (test -x /usr/local/bin/run_rrd && /usr/local/bin/run_rrd)
Mar 17 07:35:01 mythtv /USR/SBIN/CRON[5322]: (root) CMD ([ -x /usr/lib/sysstat/sa1 ] && { [ -r "$DEFAULT" ] && . "$DEFAULT" ; [ "$ENABLED" = "true
" ] && exec /usr/lib/sysstat/sa1 $SA1_OPTIONS 1 1 ; })
Mar 17 07:35:01 mythtv anacron[5281]: Job `cron.daily' started
Mar 17 07:35:01 mythtv anacron[5328]: Updated timestamp for job `cron.daily' to 2007-03-17


I'm not clear on what is happening there, but I know that the one script I want to run daily is not running, and my mythbackend is failoing because the disk is getting full of mysql binlogs.
Code:
root@mythtv:~# ll /etc/cron.daily/
total 64K
-rwxr-xr-x 1 root root   83 Feb 20 16:25 00_purge_mysql_logs.sh
-rwxr-xr-x 1 root root  311 Oct 14 09:39 0anacron
-rwxr-xr-x 1 root root 5.0K Oct 11 03:07 apt
-rwxr-xr-x 1 root root  314 Oct 27 00:49 aptitude
-rwxr-xr-x 1 root root  502 Aug 15  2006 bsdmainutils
-rwxr-xr-x 1 root root  314 Aug 31  2006 dlocate
-rwxr-xr-x 1 root root  419 Aug  6  2006 find
-rwxr-xr-x 1 root root  946 Oct 10 12:06 man-db
-rwxr-xr-x 1 root root   86 Jun  3  2006 modutils
-rwxr-xr-x 1 root root 1.2K Oct 21 10:37 ntp
-rwxr-xr-x 1 root root  383 Oct 21 06:02 samba
-rwxr-xr-x 1 root root 3.3K Oct 12 14:55 standard
-rwxr-xr-x 1 root root 1.2K Sep 28 14:48 sysklogd
-rwxr-xr-x 1 root root  469 Aug 27  2006 sysstat
-rwxr-xr-x 1 root root   89 Apr  8  2006 zz_logrotate
root@mythtv:~# cat /etc/cron.daily/00_purge_mysql_logs.sh
#!/bin/sh

rm `find /var/log/mysql -name 'mysql-bin.[0-9]*'|sort -r|sed -e '1,4d'`


Can anyone shed some light on this?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 18, 2007 7:12 am 
Offline
Joined: Wed Nov 16, 2005 8:55 pm
Posts: 1381
Location: Farmington, MI USA
I don't believe cron is your culprit here. Does MySQL still have those file open? Use lsof | grep mysql to find out. Does your script work from the command line?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 18, 2007 2:08 pm 
Offline
Joined: Tue Aug 16, 2005 11:50 am
Posts: 181
Location: Douglasville, GA
Yes, it works from the command line via sudo. That's how I do my maintenance right now, it just sucks that I have to remember to do it.

It's the anacron that confuses me, I guess. I looked at the cron lines and tested the logic from the CLI like so:
Code:
test -x /usr/sbin/anacron || echo yes


...and I get nothing. So, the lines that look like:
Code:
Mar 17 06:25:01 mythtv /USR/SBIN/CRON[4616]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))


are all duds. The only hope my /etc/cron.*/* scripts have is that this line actually causes them to get called:
Code:
Mar 17 07:30:01 mythtv /USR/SBIN/CRON[5260]: (root) CMD (test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 4:18 pm 
Offline
Joined: Wed Nov 16, 2005 8:55 pm
Posts: 1381
Location: Farmington, MI USA
RichardBronosky wrote:
Yes, it works from the command line via sudo. That's how I do my maintenance right now, it just sucks that I have to remember to do it.

It's the anacron that confuses me, I guess. I looked at the cron lines and tested the logic from the CLI like so:
Code:
test -x /usr/sbin/anacron || echo yes


...and I get nothing.
Ahhh, OK, so you do have anacron installed? On my R5D1 system it is not, so I (stupidly) ass-u-med you didn't have it.

I don't know anything at all about anacron, but I did find a README in /usr/share/doc/cron which indicates a config file (/etc/anacrontab) which you may have to play with.

Alternatively you could create your own entry in the crontab file and skip anacron altogether. This (possibly stupidly) assumes you have regular cron installed.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 7:23 pm 
Offline
Joined: Tue Aug 16, 2005 11:50 am
Posts: 181
Location: Douglasville, GA
I think I installed anacron trying to fix the problem of my cron job not running.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 2:17 am 
Offline
Joined: Mon Jun 21, 2004 5:28 am
Posts: 700
Location: Germany
Starting in one of the E releases, mail was removed. Cron mails stdout and stderr to the owner. If mail is not installed, cron does not complete.

You might try adding >/dev/null &2>1 to the end of your cron job. Example:
Code:
0 3 * * * * /myth/bin/myjob.sh >/dev/null &2>1
to see if that is the problem.

EDIT: Rereading your post, I see you are trying to add an entry into cron.daily. You might try putting an entry into crontab directly for your job (see above for an example).

Allen

_________________
ASUS AT3N7A-I (Atom 330)
TBS 8922 PCI (DVB-S2)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 8:41 am 
Offline
Joined: Tue Aug 16, 2005 11:50 am
Posts: 181
Location: Douglasville, GA
a few followups:
1. By checking "ls -lc /var/cache/apt/archives/" (This is a new Linux skill for me. It like a having a log of when you install what.) I verified that I did indeed add anacron. (I assumed it was missing from my system because of a goofy upgrade path)
2. Adding an explicit "/etc/cron.daily/00_purge_mysql_logs.sh > /dev/null" to /etc/crontab did work, so the lack of mail was probably the reason things where failing.
3. Anacron doesn't seem to read the regular /etc/crontab. Since all the lines had that "test -x" in them, installing anacron is going to prevent those lines from getting called. So, I apt-get removed it.
--*Actually, I'm not sure if anacron looks at /etc/crontab. I do know that it has its own /etc/anacrontab, so I am assuming. However, logically, even if anacron did try to execute the contents of /etc/crontab, the "test -x" lines STILL wouldn't get past the || ("OR clause") So the point is, adding anacron was wrong of me. If I want anacron, I need to do a lot of work to get harmony restored.
4. According to http://www.rt.com/man/crontab.5.html (but the man page on KM looks like this one) you can add a MAILTO="" to your crontab to prevent mail from being sent. I'm investigating where or not this eliminates the need to redirect everything to /dev/null. I want to resolve this delicacy in cron. cron is a workhorse. It needs to be solid, not fickle. I'm going to try to get a solution into the next KM release.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 10:31 am 
Offline
Joined: Tue Aug 16, 2005 11:50 am
Posts: 181
Location: Douglasville, GA
Whoa! here is a development:
Code:
root@mythtv:/# cd /etc/cron.hourly/
root@mythtv:/etc/cron.hourly# ll
total 24K
-rwxr-xr-x 1 root root 54 Mar 20 11:41 1_test.sh
-rwxr-xr-x 1 root root 34 Mar 20 12:13 2_test.sh
lrwxrwxrwx 1 root root  9 Mar 20 11:47 3_test.sh -> 1_test.sh
-rwxr-xr-x 1 root root 49 Mar 20 10:21 4_test.sh
-rwxr-xr-x 1 root root 26 Mar 20 11:41 5_test.sh
-rwxr-xr-x 1 root root 34 Mar 20 10:21 6_test.sh
-rwxr-xr-x 1 root root 50 Dec  6 23:46 pretty
root@mythtv:/etc/cron.hourly# run-parts -v /etc/cron.hourly
run-parts: executing /etc/cron.hourly/pretty
root@mythtv:/etc/cron.hourly# ./pretty
root@mythtv:/etc/cron.hourly# mv pretty /tmp
root@mythtv:/etc/cron.hourly# run-parts -v /etc/cron.hourly
root@mythtv:/etc/cron.hourly# mv 1_test.sh 1_test   
root@mythtv:/etc/cron.hourly# run-parts -v /etc/cron.hourly
run-parts: executing /etc/cron.hourly/1_test
root@mythtv:/etc/cron.hourly# for x in $(ls *.sh); do mv $x ${x%.*};done
root@mythtv:/etc/cron.hourly# run-parts -v /etc/cron.hourly
run-parts: executing /etc/cron.hourly/1_test
run-parts: executing /etc/cron.hourly/2_test
run-parts: run-parts: component /etc/cron.hourly/3_test is a broken symbolic link

run-parts: executing /etc/cron.hourly/4_test
run-parts: executing /etc/cron.hourly/5_test
run-parts: executing /etc/cron.hourly/6_test


After the first run-parts, I thought pretty must be returning non-zero (an error). So I continued to produce a control group. It looks as though run-parts will not run *.sh files. Is this common?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 10:57 am 
Offline
Joined: Mon Jun 21, 2004 5:28 am
Posts: 700
Location: Germany
RichardBronosky wrote:
After the first run-parts, I thought pretty must be returning non-zero (an error). So I continued to produce a control group. It looks as though run-parts will not run *.sh files. Is this common?
Hmmm.... I just checked the man page: "If the --lsbsysinit option is not given then the names must consist entirely of upper and lower case letters, digits, underscores, and hyphens. " That's weird. No ".". No idea why, but that's the way it is.

Cheers,

Allen

_________________
ASUS AT3N7A-I (Atom 330)
TBS 8922 PCI (DVB-S2)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 11:08 am 
Offline
Joined: Tue Aug 16, 2005 11:50 am
Posts: 181
Location: Douglasville, GA
As I've stated many times, I'm a Linux server guy so this x11/Desktop/Workstation stuff is all new to me. I checked on one of my REH4 boxes and this is what I found:
Code:
rbronosky@db1:~$ less `which run-parts`
#!/bin/bash

# run-parts - concept taken from Debian

# keep going when something fails
set +e

if [ $# -lt 1 ]; then
        echo "Usage: run-parts <dir>"
        exit 1
fi

if [ ! -d $1 ]; then
        echo "Not a directory: $1"
        exit 1
fi

# Ignore *~ and *, scripts
for i in $1/*[^~,] ; do
        [ -d $i ] && continue
        # Don't run *.{rpmsave,rpmorig,rpmnew,swp} scripts
        [ "${i%.rpmsave}" != "${i}" ] && continue
        [ "${i%.rpmorig}" != "${i}" ] && continue
        [ "${i%.rpmnew}" != "${i}" ] && continue
        [ "${i%.swp}" != "${i}" ] && continue
        [ "${i%,v}" != "${i}" ] && continue

        if [ -x $i ]; then
                $i 2>&1 | awk -v "progname=$i" \
                              'progname {
                                   print progname ":\n"
                                   progname="";
                               }
                               { print; }'
        fi
done

exit 0
/usr/bin/run-parts (END)


On KM, however, run-parts is a binary. And as you reported, has some very different properties. What a rats nest! So, the problem has been the script filename this whole time. I wonder where this leaves me with the "no mail in KM, must redirect to /dev/null" issue. Does it even matter? I'll keep testing scenarios.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 11:12 am 
Offline
Joined: Wed Nov 16, 2005 8:55 pm
Posts: 1381
Location: Farmington, MI USA
RichardBronosky wrote:
After the first run-parts, I thought pretty must be returning non-zero (an error). So I continued to produce a control group. It looks as though run-parts will not run *.sh files. Is this common?
Seems to be by design. From man run-parts:

Quote:
If the --lsbsysinit option is not given then the names must consist entirely of upper and lower case letters, digits, underscores, and
hyphens.

Although I admit I don't understand their explanation of the --lsbsysinit option...

EDIT: Looks like you found the answer before I posted...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 10:18 pm 
Offline
Joined: Tue Aug 16, 2005 11:50 am
Posts: 181
Location: Douglasville, GA
Okay, so here is the scenario I've been testing with:
Code:
mythtv@mythtv:/etc/cron.hourly$ ll
total 20
-rwxr-xr-x 1 root root 54 Mar 21 00:11 1_test
-rwxr-xr-x 1 root root 34 Mar 21 00:11 2_test
lrwxrwxrwx 1 root root  6 Mar 21 00:07 3_test -> 2_test
-rwxr-xr-x 1 root root 49 Mar 21 00:11 4_test
-rwxr-xr-x 1 root root 49 Mar 21 00:11 5_test
-rwxr-xr-x 1 root root 34 Mar 21 00:11 6_test
mythtv@mythtv:/etc/cron.hourly$ for x in $(ls *); do echo "## "FILE:$x;cat $x;done
## FILE:1_test
#!/bin/sh
date>>/tmp/crontest
echo $0>>/tmp/crontest

## FILE:2_test
#!/bin/sh
echo $0>>/tmp/crontest

## FILE:3_test
#!/bin/sh
echo $0>>/tmp/crontest

## FILE:4_test
#!/bin/sh
echo $0>>/tmp/crontest
cd /etc
ls -la

## FILE:5_test
#!/bin/sh
cd /etc
ls -la
echo $0>>/tmp/crontest

## FILE:6_test
#!/bin/sh
echo $0>>/tmp/crontest


Without adding a blank MAILTO var definition to /etc/crontab, /tmp/crontest show that it was not making it past 4_test. Adding the MAILTO made it complete all, even with garbage getting sent to STDOUT and even without having redirects to /dev/null.

The following need to get added to /etc/crontab if there is any chance that any entry in a cron job could return a message to STDOUT or STDERR.
Code:
MAILTO=""


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu