Hello all,
I'm new here and have a question if you don't mind helping me. I have a script that will work if I kick if off manually but not from Cron. My cron entry is this:
#!/bin/sh
#
# ****************************************************************************************
# Purpose: Script to check the status of the following:
# Disk usage - Call mon_fs.sh (this is dependent on mon_fs.dat
# Memory Usage - memorywatcher.sh
# MWTM Server process - ServerUporDown.sh (this is dependent on /NOT.txt file
# Notifies via e-mail.
# Usage: Execute from crontab every 15 minutes.
# Outputs: None - if one of the child scripts detects and error it will email the group
# ****************************************************************************************
# The directory this script resides in
ADMINDIR=/scripts
# remove old status.log file
rm /scripts/status.log
# Fist 2 scripts to monitor disks and memory
/scripts/mon_fs.sh
# section to run the server status command
/opt/CSCOsgm/bin/mwtm status >> /scripts/status.log
# script to determine if any of the server process are down.
/scripts/ServerUporDown.sh
At the end of that script it call another one (the broken one) called ServerUporDown.sh. This is the one that is not working.
#!/bin/ksh
# ****************************************************
# Porpose: Montior Status of server components
# Notifies on trigger via eamil
# Usage: Execute from Crontab every 15 miniuites
# Outputs: email
# ***************************************************
#
# The directory this script resides in
ADMINDIR=/scripts
#
# The next variable can be set for multiple addresses
# (i.e. jsmith@yahoo.com,jsmith@hotmail.com)
MAILADD=abc@mail.com
# Define the hostname of the server
SRVNM=`uname -n`
# Remove old file
rm /scripts/NOT.txt
# location of error messages
more /scripts/status.log | grep NOT >> /scripts/NOT.txt
# Logic to check if anything was written to the NOT file
# and email group if error was found
if [ ! -s "/scripts/NOT.txt" ]
then
echo "No error found."
else
echo "Sending eamil"
mailx -s $SRVNM" Server down - Action required" $MAILADD < NOT.txt
fi
exit 0
I'm sure it something simple... everything about it work fine but won't email that result when there is a entry into the NOT.txt file. It updates the status.log file and the NOT.txt file according the time stamps as it should.
methyl - Thanks... staring at it too long and being up for 20+ hours... need sleep.. should have seen that. After making that change... all still the same.... everything works up to the point of email me
The untrapped output from the script should be in the unix mail file for the owner of the cron.
Check whether the "Sending eamil" (sic) message appears in that mailbox and whether there are any other error messages.
You might want to redirect the cron output to a logfile and not to /dev/null while you are testing.
I'd certainly move this quote to encompass the whole subject line but whether it causes trouble depends on the value of $SRVNM.
mailx -s "$SRVNM Server down - Action required" $MAILADD < /scripts/NOT.txt
#!/bin/ksh
# ****************************************************
# Porpose: Montior Status of server components
# Notifies on trigger via eamil
# Usage: Execute from Crontab every 15 miniuites
# Outputs: email
# ***************************************************
#
# The directory this script resides in
ADMINDIR=/scripts
#
# The next variable can be set for multiple addresses
# (i.e. jsmith@yahoo.com,jsmith@hotmail.com)
MAILADD=abc@abc.com
# Define the hostname of the server
SRVNM=`uname -n`
# Remove old file
rm /scripts/NOT.txt
# location of error messages
grep "NOT" /scripts/status.log >> /scripts/NOT.txt
# Logic to check if anything was written to the NOT file
# and email group if error was found
if [ ! -s "/scripts/NOT.txt" ]
then
echo "No error found."
else
echo "Sending eamil"
mailx -s "$SRVNM Server down - Action required" $MAILADD < /scripts/NOT.txt
fi
exit 0
It has gone thru 2 cycles. Looks like a mail problem but I more in the dark now... when I cat a file and mailx it to myself it works (cat /etc/hosts | mailx abc@abc.com) , this script works when I force it with ./ServerUporDown.sh