Xymon Mailing List Archive search

Contents of root's crontab in ps list?

list Jeremy Laidman
Thu, 5 Feb 2015 20:44:14 +1100
Message-Id: <CAAnki7CdQPoQVnOw8ky5KT=P_YLycxNKrriAadp2hm=user-c62f80a7e094@xymon.invalid>

On 05/02/2015 2:30 PM, "John Palys" <user-6ab3068b00ee@xymon.invalid> wrote:
A simple script. Same script is running on all servers, only some have
the issue reported.
Probably because its only sometimes that the xymon client script runs at
the same time as the cron job. You'll probably find that they drift out of
sync over time, and different servers will be showing this phenomenon at
different times, because the xymon client script runs slightly later each
time (ie not exactly every 5 minutes).
LOGFILE=/tmp/cron_list.log

cat /var/spool/cron/root > /tmp/cron_list.log
snip (why not use $LOGFILE here)
cat /var/spool/cron/cworks >> /tmp/cron_list.log
RESULT=`cat $LOGFILE`


LINE="status $MACHINE.$TEST $COLOR `date`

$RESULT"

$XYMON $XYMSRV "$LINE"
This is the problem. The contents of cron_list.log (ie a copy of the
crontab) is put into $RESULT and in turn into $LINE. Then the text is given
to the xymon command as a parameter, for all to see in ps output.

As soon as you use backticks, you're going to get into trouble. You can't
do anything useful with $RESULT without its contents appearing on a command
line in ps output, should it happen to run at the same time.

Instead, use the alternative form of running xymon, by specifying a
parameter of "@" and feeding the message on stdin.  Like so:

LINE="status $MACHINE.$TEST $COLOR `date`
{ echo "$LINE"; echo; cat $LOGFILE; } | $XYMON $XYMSRV "@"

And get rid of the line that sets $RESULT cos you don't need it anymore.

J
 Jeremy,

A simple script. Same script is running on all servers, only some have the
issue reported.  The xymon ../ext/crontab.sh which sends the output TO the
xymon server is identical to the mis-behaving servers.

#!/bin/bash

LOGFILE=/tmp/cron_list.log

cat /var/spool/cron/root > /tmp/cron_list.log

if [ -f /var/spool/cron/cworks ]; then
echo "================================" >> /tmp/cron_list.log

cat /var/spool/cron/cworks >> /tmp/cron_list.log

else echo ""
fi
#!/bin/sh

#

# Standard XYMON stuff

#

if [ "$XYMONHOME" = "" ]; then

   echo "XYMONHOME is not set... exiting"

   exit 1

fi


if [ ! "$XYMONTMP" ]; then

   . $XYMONHOME/etc/bbdef.sh

fi


#-----------------------

# EDIT Variables here

#-----------------------

TEST=crontab
COLOR=green
LOGFILE=/tmp/cron_list.log
TMPFILE=$XYMONHOME/tmp/$TEST.tmp

RESULT=`cat $LOGFILE`


LINE="status $MACHINE.$TEST $COLOR `date`

$RESULT"

$XYMON $XYMSRV "$LINE"

#rm -f $BBTMP/$TEST.tmp

#rm -f $TMPFILE

On Wed, Feb 4, 2015 at 6:54 PM, Jeremy Laidman <user-71895fb2e44c@xymon.invalid>
wrote:
Ben

On 5 February 2015 at 13:03, Benjamin Smith <user-bd60c1f964ce@xymon.invalid>
wrote:

# cat crontab files to /tmp/cron_list.log for xymon crontab.sh
0 * * * * /root/bin/std/show_crontab.sh??#XYMON?#?
What does this script (show_crontab.sh) do?

Cheers
Jeremy
-- 
John Palys
School Pathways, Inc.
XXX-XXX-XXXX #2010 * Office*