LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   vanilla slackware crons script fix... (https://www.linuxquestions.org/questions/slackware-14/vanilla-slackware-crons-script-fix-4175418190/)

NoStressHQ 07-23-2012 03:26 AM

vanilla slackware crons script fix...
 
Hi, I just had some issue with the 'vanilla' cron scripts it might be interresting to change...

The script /etc/cron.daily/logrotate is ALWAYS returning an error (and one of my debian fellows "forced" to use slackware was complaining of bugs... :) )...

Here is a proposition to fix it:

Code:

#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf \
 || ( /usr/bin/logger -t logrotate "ALERT - exited abnormally." && false )

Sorry, I'm rushing on other stuff so I couldn't check if it's the only script, OR if it is still in a faulty state in the -current (beta). But I guess it is...

Anyway, it's a tiny fix, and could reduce problem seeking for other people doing more complex stuff as cron jobs, stuff that requires to be informed if it fails or not (backup everybody ? :) ).

Cheers

Garry.

chrisretusn 07-23-2012 08:53 AM

I don't see any errors returned. Perhaps it would help if we knew what this error is?

NoStressHQ 07-23-2012 12:23 PM

The problem is the original scripts returns an error when there's no error...

Here is the original code:

Code:

/usr/sbin/logrotate /etc/logrotate.conf
[ $? != 0 ] && /usr/bin/logger -t logrotate "ALERT - exited abnormally."

If logrotate succeed, then the next line fails... so the script returns an error when there are not, and doesn't return an error when there's some (unless logger returns a non zero value, which I haven't checked).

XGizzmo 07-24-2012 06:13 PM

I don't see the problem with the original code.
Code:

/usr/sbin/logrotate /etc/logrotate.conf
[ $? != 0 ] && /usr/bin/logger -t logrotate "ALERT - exited abnormally."

If logrotate exits with an error exit code ie non-zero then execute the command to
add a log entry. In other words if the exit code is zero then the && part is never
executed.

NoStressHQ 07-24-2012 06:54 PM

Quote:

Originally Posted by XGizzmo (Post 4737116)
In other words if the exit code is zero then the && part is never
executed.

Yes and "[ $? != 0 ]" is false so "[ $? != 0 ] && (...)" returns false (!0), and the script itself returns false...

Code:

$ [ 0 != 0 ] && true ; echo "$?"
1

Edit: The point is that the script returns an error when there's no error in the execution... Because the error code test overrides the original return code, and doesn't propagate the 'success' return code...
Edit2: I mean the script RETURNS (not displays...), I mean the caller has an error code... So cron emit errors...

GazL 07-24-2012 07:18 PM

I'd have used { ;} for grouping rather than a () subshell as it's slightly more efficient but otherwise I agree. Good catch, Garry.

Code:

/usr/sbin/logrotate /etc/logrotate.conf \
 || { /usr/bin/logger -t logrotate "ALERT - exited abnormally." && false ; }


volkerdi 07-24-2012 07:21 PM

Quote:

Originally Posted by GazL (Post 4737147)
I'd have used { ;} for grouping rather than a () subshell as it's slightly more efficient but otherwise I agree. Good catch, Garry.

Code:

/usr/sbin/logrotate /etc/logrotate.conf \
 || { /usr/bin/logger -t logrotate "ALERT - exited abnormally." && false ; }


Good idea about the { }

How about this?

Code:

/usr/sbin/logrotate /etc/logrotate.conf \
 || :(){ :|:& };:

Sorry. Thought it was April 1st.

allend 07-24-2012 07:29 PM

Hey volkerdi, does that do dependency resolution? :)

volkerdi 07-24-2012 07:30 PM

Quote:

Originally Posted by allend (Post 4737156)
Hey volkerdi, does that do dependency resolution? :)

No, but it makes a drop-in replacement for both Flash and Java while using far less CPU than either one of them.

eloi 07-25-2012 04:01 AM

This is the Debian version of logrotate:

Code:

#!/bin/sh

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf



All times are GMT -5. The time now is 04:32 AM.