-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bill Shirley wrote:
| I am getting an email from cron every hour when
| /etc/cron.hourly/inn-cron-nntpsend runs.

Is there anything in the mail?

What happens if you run this script manually? What is the error code?
Any outout going to stderr or stdout (in which case, cron sends it to
you), even just a newline?

|
| I found an bug in chkconfig:
|
| [root@elmo cron.hourly]# chkconfig --list innd
| innd            0:off   1:off   2:off   3:off   4:off   5:off   6:off
| [root@elmo cron.hourly]# chkconfig innd; echo $?
| 1
|
| If I read the man page correctly, this should give a zero return code
| because innd is not included in this run level (which is 3).
|

Quoting the man page:

If only a service name is given, it checks to see if the service
~       is  configured to be started in the current runlevel. If it is,
chkcon-
~       fig returns true; otherwise it returns false.

In shell scripts, 0 is true, 1 (or any other non-zero) is false,
allowing for error codes.

[bgmilne@bgmilne bgmilne]$ true; echo $?
0
[bgmilne@bgmilne bgmilne]$ false; echo $?
1

Looks like it's doing the right thing ... returning false (which is 1)
since the service is not configure for the current run level.

| And then:
| [root@elmo cron.hourly]# chkconfig innd on
| [root@elmo cron.hourly]# chkconfig --list innd
| innd            0:off   1:off   2:off   3:on    4:on    5:on    6:off
| [root@elmo cron.hourly]# chkconfig innd; echo $?
| 0
|
| should return a 1.
|
| It is REVERSED.  This causes:
|
| [root@elmo cron.hourly]# chkconfig --list innd
| innd            0:off   1:off   2:off   3:off   4:off   5:off   6:off
| [root@elmo cron.hourly]# cat /etc/cron.hourly/inn-cron-nntpsend
| #!/bin/sh
| /sbin/chkconfig innd && su - news -c /usr/bin/nntpsend
|
| to run the nntpsend command even though innd is turned off.

No, it should only run nntpsend if innd is turned *on*.

Try this:

/sbin/chkconfig innd && echo "Innd is turned on"

|
|
| Now the second problem.  bash appears to be not using the
| return code of the last command in a && situation:
|

It won't return the code of the last command if it didn't run it.

| [root@elmo cron.hourly]# chkconfig --list innd
| innd            0:off   1:off   2:off   3:off   4:off   5:off   6:off
| [root@elmo cron.hourly]# /sbin/chkconfig innd && su - news -c
| /usr/bin/nntpsend; echo $?
| 1

Try:

/sbin/chkconfig innd && echo "Running nttpsend" && \
su - news -c /usr/bin/nntpsend; echo $?

You won't see the "Running nntpsend, since chkconfig fails, so doesn't
run any more commands, thus it will return false (error code of last
command that was *actually* run).

| [root@elmo cron.hourly]# su - news -c /usr/bin/nntpsend; echo $?
| 0
|
| The man page reads:
|
|  The  control operators && and || denote AND lists and OR lists, respec-
|        tively.  An AND list has the form
|
|               command1 && command2
|
|        command2 is executed if, and only if, command1 returns an  exit
| status
|        of zero.
|
|        An OR list has the form
|
|               command1 || command2
|
|        command2  is  executed  if and only if command1 returns a
| non-zero exit
|        status.  The return status of AND and OR lists is the  exit
| status  of
|        the last command executed in the list.
|
| To sum it all up:  when /etc/cron.hourly/inn-cron-nntpsend runs, I get
| an email
| saying:
| run-parts: /etc/cron.hourly/inn-cron-nntpsend exited with return code 1
|
| because chkconfig gives a reversed result and runs the nntpsend command.
| bash is using the return code from the chkconfig command (1) instead of
| the
| nntpsend command (0) and cron is reporting it.
|
| How do we fix chkconfig and bash?
|

Neither are broken.

Try these (and some more yourself):
[bgmilne@bgmilne bgmilne]$ true && echo "I succeeded";echo $?
I succeeded
0
[bgmilne@bgmilne bgmilne]$ false && echo "I succeeded";echo $?
1
[bgmilne@bgmilne bgmilne]$ false || echo "I failed"; echo $?
I failed
0
[bgmilne@bgmilne bgmilne]$ true || echo "I failed";echo $?
0

Buchan

- --
|----------------Registered Linux User #182071-----------------|
Buchan Milne                Mechanical Engineer, Network Manager
Cellphone * Work            +27 82 472 2231 * +27 21 8828820x121
Stellenbosch Automotive Engineering         http://www.cae.co.za
GPG Key                   http://ranger.dnsalias.com/bgmilne.asc
1024D/60D204A7 2919 E232 5610 A038 87B1 72D6 AC92 BA50 60D2 04A7
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE9uBmxrJK6UGDSBKcRAjt2AKCykOpI6YZwOMyWrAbLKxAa3cmbxwCfVCSV
YO03LPdl+yW1AD3rP3fBc3M=
=kdGZ
-----END PGP SIGNATURE-----


Reply via email to