Better item logging and error handling.

This commit is contained in:
Louwrentius 2009-03-01 16:47:44 +00:00
parent 66a8983a3e
commit 6bd4d48a76

30
ppss.sh
View File

@ -163,7 +163,7 @@ exec_cmd () {
does_file_exist () { does_file_exist () {
FILE="$1" FILE="$1"
`exec_cmd "ls -1 $FILE >> /dev/null 2>&1"` `exec_cmd "ls -1 $FILE" >> /dev/null 2>&1`
if [ "$?" == "0" ] if [ "$?" == "0" ]
then then
return 0 return 0
@ -986,29 +986,35 @@ commando () {
else else
ERROR="" ERROR=""
# Some formatting of item log files.
DATE=`date +%b\ %d\ %H:%M:%S`
echo "=== PPSS Item Log File ===" > "$ITEM_LOG_FILE"
echo -e "Host:\t$HOSTNAME" >> "$ITEM_LOG_FILE"
echo -e "Date:\t$DATE" >> "$ITEM_LOG_FILE"
echo -e "Item:\t$ITEM" >> "$ITEM_LOG_FILE"
# The actual execution of the command.
TMP=`echo $COMMAND | grep -i '$ITEM'` TMP=`echo $COMMAND | grep -i '$ITEM'`
if [ "$?" == "0" ] if [ "$?" == "0" ]
then then
echo "=================" > "$ITEM_LOG_FILE"
echo "HOST = $HOSTNAME" >> "$ITEM_LOG_FILE"
echo "ITEM = $ITEM" >> "$ITEM_LOG_FILE"
##ESCAPED=`echo "$ITEM" | sed -e s:\\\\\/:\\\\\\\\/:g`
#COMMAND=`echo $COMMAND | sed -e s:%ITEM%:"$ESCAPED":g`
#echo "COMMAND is $COMMAND" >> "$ITEM_LOG_FILE"
eval "$COMMAND" >> "$ITEM_LOG_FILE" 2>&1 eval "$COMMAND" >> "$ITEM_LOG_FILE" 2>&1
ERROR="$?" ERROR="$?"
else else
EXECME='$COMMAND"$ITEM" >> "$ITEM_LOG_FILE" 2>&1' EXECME='$COMMAND"$ITEM" >> "$ITEM_LOG_FILE" 2>&1'
echo EXECME is "$EXECME"
eval "$EXECME" eval "$EXECME"
ERROR="$?" ERROR="$?"
fi fi
if [ ! "$ERROR" == "0" ] && [ "$TRANSFER_TO_SLAVE" == "1" ] # Some error logging. Success or fail.
if [ ! "$ERROR" == "0" ]
then then
mv $ITEM $ITEM.error echo -e "Status:\tError - something went wrong." >> "$ITEM_LOG_FILE"
elif [ "$TRANSFER_TO_SLAVE" == "1" ] else
echo -e "Status:\tSucces - item has been processed." >> "$ITEM_LOG_FILE"
fi
if [ "$TRANSFER_TO_SLAVE" == "1" ]
then then
if [ -e "$ITEM" ] if [ -e "$ITEM" ]
then then