LinuxQuestions.org

LinuxQuestions.org (http://www.linuxquestions.org/questions/index.php)
-   Slackware (http://www.linuxquestions.org/questions/forumdisplay.php?f=14)
-   -   [Cron jobs] More error reporting... (http://www.linuxquestions.org/questions/showthread.php?t=4175418742)

NoStressHQ 07-26-2012 04:39 AM

[Cron jobs] More error reporting...
 
Hi,

Right now, the vanilla setup of crontab, prevents us to receive failure mail. Because:

- contrab is redirecting stdout to /dev/null
- run-parts is always emitting something and redirect stderr script channel into the stdout channel (so it goes into garbage).

We were able to fix all this with:
1) fixing /usr/bin/run-parts (see below).
2) removing the "1> /dev/null" from the cron tab.

run-parts original code:
Code:

  # If we've made it this far, then run the script if it's executable:
  if [ -x $SCRIPT ]; then
    echo "$SCRIPT:"
    echo
    $SCRIPT 2>&1
    echo
    ...

Our fix on run-parts:
Code:

  # If we've made it this far, then run the script if it's executable:
  if [ -x $SCRIPT ]; then
    $SCRIPT 2>&1 || echo "$SCRIPT failed."
    ...

I guess we even should be able to just do
Code:

$SCRIPT || echo "$SCRIPT failed." 1>&2
which seems to me as even better.


Everything run smoothly, the only mail we have are "errors". Note that we CAN receive mail if something outputs to stdout, but usually a good unix tool, run silently if no error, and if it verbose something, its better(/easy) just to redirect THAT call and not everything...

Of course part of the comment on top of crontab might be deprecated if those fix are applied :).

Obviously, cron jobs scripts should have a normal behavior (we had to fix logrotate too, see this thread)...

Cheers

Garry.

NoStressHQ 07-26-2012 06:57 AM

Just to quote the comment on top of the cron tab:
Code:

# If you don't want the output of a cron job mailed to you, you have to direct
# any output to /dev/null.  We'll do this here since these jobs should run
# properly on a newly installed system, but if they don't the average newbie
# might get quite perplexed about getting strange mail every 5 minutes. :^)

I think all those fixes make this comment a bit deprecated, as there shouldn't be any "strange mail every 5 minutes" BUT the real error notification, and you WILL have the error notifications (instead of nothing).

That's all... Sorry, we're in delivery time here, it's hot, and didn't had the time (/mind) to pack all those in one post. :)

Cheers

Garry.

NoStressHQ 08-01-2012 07:51 AM

Sorry to bump this, but is it irrelevant ? Do I need to provide more information ? Does it introduce a risk of breaking something ? Anything ? :)

Cheers

Garry.

Habitual 08-01-2012 01:08 PM

and I thought it was just "me"...
The only 2 mails I have ever received are
Code:

sudo mail -u root
Heirloom mailx version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/root": 2 messages 2 unread
>U  1 To root            Thu Mar 10 23:33  53/1912  Register with the Linux counter project
 U  2 To root            Thu Mar 10 23:35  322/15427 Welcome to Linux (Slackware 13.37)!

15 day old system. Stock+KDE

Code:

    35      # If we've made it this far, then run the script if it's executable:
    36      if [ -x $SCRIPT ]; then
    37        echo "$SCRIPT:"
    38        echo
    39        $SCRIPT 2>&1
    40        echo
    41      fi
    42    done

I made the suggest change and sorta hoping it works. :)

Subscribed with Interest...

JJ

NoStressHQ 08-02-2012 06:57 AM

Quote:

Originally Posted by Habitual (Post 4743365)
and I thought it was just "me"...

Hehe, me too. Maybe I should have asked about automatic dependencies so I would have more reactions :).

I might have chosen the title badly tho.

Hey Habitual, you have quite an interesting blog, a great snippet vault!

Cheers

Garry.

Habitual 08-02-2012 07:15 AM

Quote:

Originally Posted by NoStressHQ (Post 4744015)
...you have quite an interesting blog, a great snippet vault!

Cheers

Garry.

Thanks, it's just a place to store stuff so my brain can focus on learning more stuff.

Peace.

P.S. Tomorrow, I have another cron set to run at 8am EDT, so I'm hoping...

Any clues in the cron log(s)?

NoStressHQ 08-02-2012 08:34 AM

Quote:

Originally Posted by Habitual (Post 4744033)
Any clues in the cron log(s)?

If you're asking me, we had to do those fix some time ago in order to have a proper setup for our automatic backup of our server, so we have no problem since then, when we had mails it was because of real failures/errors, rest of the time it's silent. And everything is working smoothly. Well technically, I'm sure we solve a problem and didn't introduced any, I mean we really know what we do, on the other hand, experience told me that "we never know" so I'm open to any report.

I just wish it could be integrated in stock slackware, as for my point of view it's a real fix of a real "bug"... (and it's more in the 'vanilla' philosophy of slackware than the existing code IMHO).


All times are GMT -5. The time now is 06:28 AM.