I am getting an email from cron every hour when
/etc/cron.hourly/inn-cron-nntpsend runs.
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).
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.
Now the second problem. bash appears to be not using the
return code of the last command in a && situation:
[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
[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?
Bill Shirley