line 220 : return: can can only 'return' from a function or sourced script
-1
# C A L L C U S T O M E R D E F I N E D P A R A M E T E R S
#----------------------------------------------------------------------------------
cd /ERQ/100/DM/SCRIPTS
. ./DMPR2ERQ_log_interface.env
#----------------------------------------------------------------------------------
# I N T E R N A L S E C T I O N ! ! !
#----------------------------------------------------------------------------------
ORG_PWD=$PWD # save directory where i am
COUNT=0 # actual value for retry logic
DATE=`date +'%y%m%d%H%M%S'` # creating time stamp
HUMAN_DATE=`date +'%d.%m.%Y - %H:%M:%S'` # creating human readable time stamp
TMP_LOGFILE=$LOG_FILE_OUT.$$ # temporary log file with PID
SLEEP_TIME=10 # how long to wait until check of file size
#----------------------------------------------------------------------------------
# S E N D E M A I L O N E R R O R
#----------------------------------------------------------------------------------
SUBJECT="ERROR in script send_DMPR2ERQ_log.sh for Queue $QUEUE"
function error_mail
{
BODY="nDate: $HUMAN_DATE CET
nScript: $ORG_PWD/send_DMPR2ERQ_log.sh
nServer: `hostname`
nnThe following error occured:
n----------------------------
$ERROR_MSG"
echo "$BODY" | mailx -s "$SUBJECT" "$EMAIL_ADDRESS"
}
#----------------------------------------------------------------------------------
# R E T U R N C O D E S
#----------------------------------------------------------------------------------
RC_OK=0 # used in spoolin and spoolout
RC_PARAM_ERR=1 # used in spoolin and spoolout
RC_LOG_ERR=10 # used in spoolin and spoolout
RC_SI_PATH_ERR=11 # used in spoolin
RC_SO_PATH_ERR=12 # used in spoolout
RC_ARCHIVE_PATH_ERR=13 # used in spoolin
RC_ERROR_PATH_ERR=14 # used in spoolin
RC_NO_FILES_ERR=15 # used in spoolin
RC_NO_QMGR_ERR=20 # used in spoolin and spoolout
RC_NO_QUEUE_ERR=21 # used in spoolin and spoolout
RC_NO_MQSERVER_ERR=22 # used in spoolin and spoolout
RC_DPBAT_ERR=100 # used in spoolin and spoolout
RC_NO_FILENAME_ERR=300
RC_FILENAME_ERR=310
#----------------------------------------------------------------------------------
# E R R O R S E C T I O N
#----------------------------------------------------------------------------------
SCRIPT_RC=$RC_OK # init return code
if touch $LOG_FILE_OUT # log file access?
then
echo "n["$DATE"]" > $TMP_LOGFILE
else
echo "ERROR: RC=$RC_LOG_ERR - Can't create $LOG_FILE_OUT"
return $RC_LOG_ERR
fi
VARCHECK=`echo $MHQ_MQMGRNAME | wc -w`
if [ $VARCHECK = "0" ] # Queue Manager defined?
then
echo "ERROR: RC=$RC_NO_QMGR_ERR - Queue Manager not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_NO_QMGR_ERR - Queue Manager not defined!"
SCRIPT_RC=$RC_NO_QMGR_ERR
fi
VARCHECK=`echo $QUEUE | wc -w`
if [ $VARCHECK = "0" ] # Queue defined?
then
echo "ERROR: RC=$RC_NO_QUEUE_ERR - Target Queue not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_NO_QUEUE_ERR - Target Queue not defined"
SCRIPT_RC=$RC_NO_QUEUE_ERR
fi
VARCHECK=`echo $MQSERVER | wc -w`
if [ $VARCHECK = "0" ] # MQ Server connectivity defined?
then
echo "ERROR: RC=$RC_NO_MQSERVER_ERR - Variable MQSERVER not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_NO_MQSERVER_ERR - Variable MQSERVER not defined"
SCRIPT_RC=$RC_NO_MQSERVER_ERR
fi
VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ] # Archive path defined?
then
echo "ERROR: RC=$RC_ARCHIVE_PATH_ERR - Variable ARCHIVE_PATH not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_ARCHIVE_PATH_ERR - Variable ARCHIVE_PATH not defined"
SCRIPT_RC=$RC_ARCHIVE_PATH_ERR
fi
VARCHECK=`echo $ERROR_PATH | wc -w`
if [ $VARCHECK = "0" ] # Error path defined?
then
echo "ERROR: RC=$RC_ERROR_PATH_ERR - Variable ERROR_PATH not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_ERROR_PATH_ERR - Variable ERROR_PATH not defined"
SCRIPT_RC=$RC_ERROR_PATH_ERR
fi
VARCHECK=`echo $SI_PATH | wc -w`
if [ $VARCHECK != "0" ] # parameter SI_PATH defined?
then
cd $SI_PATH
CD_RC=$?
if [ $CD_RC = "0" ]
then
echo "--> Changed to spoolin directory $SI_PATH successfully." >> $TMP_LOGFILE
else
echo "ERROR: RC=$RC_SI_PATH_ERR - could not change to spoolin directory $SI_PATH" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_SI_PATH_ERR - could not change to spoolin directory $SI_PATH"
SCRIPT_RC=$RC_SI_PATH_ERR
fi
else
echo "ERROR: RC=$RC_SI_PATH_ERR - no variable for spoolin directory specified" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_SI_PATH_ERR - no variable for spoolin directory specified"
SCRIPT_RC=$RC_SI_PATH_ERR
fi
#----------------------------------------------------------------------------------
# S P O O L I N
#----------------------------------------------------------------------------------
if [ $SCRIPT_RC -eq "0" ]
then
#----------------------------------------------------------------------------------
# F I L E P O L L I N G
#----------------------------------------------------------------------------------
cd /srv/ERQ_P2M_DUALACCESS/DM/LOG
cp `ls -tr DMPR2ERP* | tail -1` /ERQ/100/DM/OUTBOUND
cd /ERQ/100/DM/OUTBOUND
for FILE in `ls -l DMPR2ERP*`; do
if [ -f $FILE ]; then
FILE_SIZE_1=`ls -l $FILE | awk '{ printf("%s.%sn", $9, $5) }'`
sleep $SLEEP_TIME
FILE_SIZE_2=`ls -l $FILE | awk '{ printf("%s.%sn", $9, $5) }'`
if [ $FILE_SIZE_1 = $FILE_SIZE_2 ]; then
SI_FILENAME=$FILE
echo " > Putting file $SI_PATH/$SI_FILENAME to Queue $QUEUE" >> $TMP_LOGFILE
#----------------------------------------------------------------------------------
# D E T E R M I N E S P O O L I N O P T I O N
#----------------------------------------------------------------------------------
SI_CMD="si(si-id=$QUEUE, si-filename=$SI_FILENAME); end; "
DPBAT_RC=0
echo $SI_CMD | $MHQ_HOME/dpbat >> $TMP_LOGFILE 2>&1
DPBAT_RC=$?
echo "Return Code (RC) DPBAT = $DPBAT_RC" >> $TMP_LOGFILE
if [ $DPBAT_RC = "0" ]
then
#----------------------------------------------------------------------------
# if RC=0 the spool-in was succesful, move to archive directory
#----------------------------------------------------------------------------
echo "--> File $SI_PATH/$SI_FILENAME successfully put to Queue $QUEUE." >> $TMP_LOGFILE
mv $SI_PATH/$SI_FILENAME $ARCHIVE_PATH
echo "--> File $SI_PATH/$SI_FILENAME moved to archive directory. n " >> $TMP_LOGFILE
else
#----------------------------------------------------------------------------
# if RC<>0 the spool-in was NOT succesful, move to error directory
#----------------------------------------------------------------------------
SCRIPT_RC=`expr $DPBAT_RC + $RC_DPBAT_ERR` # some dpbat errors found!
echo "--> Ended without putting file to Queue. (RC DPBAT: $DPBAT_RC)" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nEnded without putting file to Queue. (RC DPBAT: $DPBAT_RC)"
mv $SI_PATH/$SI_FILENAME $ERROR_PATH
echo "--> Moved file to error directory $ERROR_PATH." >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nMoved file to error directory $ERROR_PATH."
fi
fi
fi
done
else
echo "File $FILE does not exists" >> $TMP_LOGFILE
SCRIPT_RC=15
fi
#----------------------------------------------------------------------------------
# Analyze global error return code and send email if necessary
#----------------------------------------------------------------------------------
if [ $SCRIPT_RC -ne "0" ]
then
echo "ERROR occured. (RC SCRIPT: $SCRIPT_RC)" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR occurred. (RC SCRIPT: $SCRIPT_RC)"
if [ $ERROR_NOTIFICATION = "y" ]
then
echo "Notification sent to $EMAIL_ADDRESS" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nNotification sent to $EMAIL_ADDRESS"
error_mail
fi
fi
#----------------------------------------------------------------------------------
# Append temporary log to main log and delete temporary log file
#----------------------------------------------------------------------------------
cat $TMP_LOGFILE >> $LOG_FILE_OUT
rm -f $TMP_LOGFILE
cd $ORG_PWD
return $SCRIPT_RC
shell-script scripting
New contributor
add a comment |
-1
# C A L L C U S T O M E R D E F I N E D P A R A M E T E R S
#----------------------------------------------------------------------------------
cd /ERQ/100/DM/SCRIPTS
. ./DMPR2ERQ_log_interface.env
#----------------------------------------------------------------------------------
# I N T E R N A L S E C T I O N ! ! !
#----------------------------------------------------------------------------------
ORG_PWD=$PWD # save directory where i am
COUNT=0 # actual value for retry logic
DATE=`date +'%y%m%d%H%M%S'` # creating time stamp
HUMAN_DATE=`date +'%d.%m.%Y - %H:%M:%S'` # creating human readable time stamp
TMP_LOGFILE=$LOG_FILE_OUT.$$ # temporary log file with PID
SLEEP_TIME=10 # how long to wait until check of file size
#----------------------------------------------------------------------------------
# S E N D E M A I L O N E R R O R
#----------------------------------------------------------------------------------
SUBJECT="ERROR in script send_DMPR2ERQ_log.sh for Queue $QUEUE"
function error_mail
{
BODY="nDate: $HUMAN_DATE CET
nScript: $ORG_PWD/send_DMPR2ERQ_log.sh
nServer: `hostname`
nnThe following error occured:
n----------------------------
$ERROR_MSG"
echo "$BODY" | mailx -s "$SUBJECT" "$EMAIL_ADDRESS"
}
#----------------------------------------------------------------------------------
# R E T U R N C O D E S
#----------------------------------------------------------------------------------
RC_OK=0 # used in spoolin and spoolout
RC_PARAM_ERR=1 # used in spoolin and spoolout
RC_LOG_ERR=10 # used in spoolin and spoolout
RC_SI_PATH_ERR=11 # used in spoolin
RC_SO_PATH_ERR=12 # used in spoolout
RC_ARCHIVE_PATH_ERR=13 # used in spoolin
RC_ERROR_PATH_ERR=14 # used in spoolin
RC_NO_FILES_ERR=15 # used in spoolin
RC_NO_QMGR_ERR=20 # used in spoolin and spoolout
RC_NO_QUEUE_ERR=21 # used in spoolin and spoolout
RC_NO_MQSERVER_ERR=22 # used in spoolin and spoolout
RC_DPBAT_ERR=100 # used in spoolin and spoolout
RC_NO_FILENAME_ERR=300
RC_FILENAME_ERR=310
#----------------------------------------------------------------------------------
# E R R O R S E C T I O N
#----------------------------------------------------------------------------------
SCRIPT_RC=$RC_OK # init return code
if touch $LOG_FILE_OUT # log file access?
then
echo "n["$DATE"]" > $TMP_LOGFILE
else
echo "ERROR: RC=$RC_LOG_ERR - Can't create $LOG_FILE_OUT"
return $RC_LOG_ERR
fi
VARCHECK=`echo $MHQ_MQMGRNAME | wc -w`
if [ $VARCHECK = "0" ] # Queue Manager defined?
then
echo "ERROR: RC=$RC_NO_QMGR_ERR - Queue Manager not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_NO_QMGR_ERR - Queue Manager not defined!"
SCRIPT_RC=$RC_NO_QMGR_ERR
fi
VARCHECK=`echo $QUEUE | wc -w`
if [ $VARCHECK = "0" ] # Queue defined?
then
echo "ERROR: RC=$RC_NO_QUEUE_ERR - Target Queue not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_NO_QUEUE_ERR - Target Queue not defined"
SCRIPT_RC=$RC_NO_QUEUE_ERR
fi
VARCHECK=`echo $MQSERVER | wc -w`
if [ $VARCHECK = "0" ] # MQ Server connectivity defined?
then
echo "ERROR: RC=$RC_NO_MQSERVER_ERR - Variable MQSERVER not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_NO_MQSERVER_ERR - Variable MQSERVER not defined"
SCRIPT_RC=$RC_NO_MQSERVER_ERR
fi
VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ] # Archive path defined?
then
echo "ERROR: RC=$RC_ARCHIVE_PATH_ERR - Variable ARCHIVE_PATH not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_ARCHIVE_PATH_ERR - Variable ARCHIVE_PATH not defined"
SCRIPT_RC=$RC_ARCHIVE_PATH_ERR
fi
VARCHECK=`echo $ERROR_PATH | wc -w`
if [ $VARCHECK = "0" ] # Error path defined?
then
echo "ERROR: RC=$RC_ERROR_PATH_ERR - Variable ERROR_PATH not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_ERROR_PATH_ERR - Variable ERROR_PATH not defined"
SCRIPT_RC=$RC_ERROR_PATH_ERR
fi
VARCHECK=`echo $SI_PATH | wc -w`
if [ $VARCHECK != "0" ] # parameter SI_PATH defined?
then
cd $SI_PATH
CD_RC=$?
if [ $CD_RC = "0" ]
then
echo "--> Changed to spoolin directory $SI_PATH successfully." >> $TMP_LOGFILE
else
echo "ERROR: RC=$RC_SI_PATH_ERR - could not change to spoolin directory $SI_PATH" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_SI_PATH_ERR - could not change to spoolin directory $SI_PATH"
SCRIPT_RC=$RC_SI_PATH_ERR
fi
else
echo "ERROR: RC=$RC_SI_PATH_ERR - no variable for spoolin directory specified" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_SI_PATH_ERR - no variable for spoolin directory specified"
SCRIPT_RC=$RC_SI_PATH_ERR
fi
#----------------------------------------------------------------------------------
# S P O O L I N
#----------------------------------------------------------------------------------
if [ $SCRIPT_RC -eq "0" ]
then
#----------------------------------------------------------------------------------
# F I L E P O L L I N G
#----------------------------------------------------------------------------------
cd /srv/ERQ_P2M_DUALACCESS/DM/LOG
cp `ls -tr DMPR2ERP* | tail -1` /ERQ/100/DM/OUTBOUND
cd /ERQ/100/DM/OUTBOUND
for FILE in `ls -l DMPR2ERP*`; do
if [ -f $FILE ]; then
FILE_SIZE_1=`ls -l $FILE | awk '{ printf("%s.%sn", $9, $5) }'`
sleep $SLEEP_TIME
FILE_SIZE_2=`ls -l $FILE | awk '{ printf("%s.%sn", $9, $5) }'`
if [ $FILE_SIZE_1 = $FILE_SIZE_2 ]; then
SI_FILENAME=$FILE
echo " > Putting file $SI_PATH/$SI_FILENAME to Queue $QUEUE" >> $TMP_LOGFILE
#----------------------------------------------------------------------------------
# D E T E R M I N E S P O O L I N O P T I O N
#----------------------------------------------------------------------------------
SI_CMD="si(si-id=$QUEUE, si-filename=$SI_FILENAME); end; "
DPBAT_RC=0
echo $SI_CMD | $MHQ_HOME/dpbat >> $TMP_LOGFILE 2>&1
DPBAT_RC=$?
echo "Return Code (RC) DPBAT = $DPBAT_RC" >> $TMP_LOGFILE
if [ $DPBAT_RC = "0" ]
then
#----------------------------------------------------------------------------
# if RC=0 the spool-in was succesful, move to archive directory
#----------------------------------------------------------------------------
echo "--> File $SI_PATH/$SI_FILENAME successfully put to Queue $QUEUE." >> $TMP_LOGFILE
mv $SI_PATH/$SI_FILENAME $ARCHIVE_PATH
echo "--> File $SI_PATH/$SI_FILENAME moved to archive directory. n " >> $TMP_LOGFILE
else
#----------------------------------------------------------------------------
# if RC<>0 the spool-in was NOT succesful, move to error directory
#----------------------------------------------------------------------------
SCRIPT_RC=`expr $DPBAT_RC + $RC_DPBAT_ERR` # some dpbat errors found!
echo "--> Ended without putting file to Queue. (RC DPBAT: $DPBAT_RC)" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nEnded without putting file to Queue. (RC DPBAT: $DPBAT_RC)"
mv $SI_PATH/$SI_FILENAME $ERROR_PATH
echo "--> Moved file to error directory $ERROR_PATH." >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nMoved file to error directory $ERROR_PATH."
fi
fi
fi
done
else
echo "File $FILE does not exists" >> $TMP_LOGFILE
SCRIPT_RC=15
fi
#----------------------------------------------------------------------------------
# Analyze global error return code and send email if necessary
#----------------------------------------------------------------------------------
if [ $SCRIPT_RC -ne "0" ]
then
echo "ERROR occured. (RC SCRIPT: $SCRIPT_RC)" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR occurred. (RC SCRIPT: $SCRIPT_RC)"
if [ $ERROR_NOTIFICATION = "y" ]
then
echo "Notification sent to $EMAIL_ADDRESS" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nNotification sent to $EMAIL_ADDRESS"
error_mail
fi
fi
#----------------------------------------------------------------------------------
# Append temporary log to main log and delete temporary log file
#----------------------------------------------------------------------------------
cat $TMP_LOGFILE >> $LOG_FILE_OUT
rm -f $TMP_LOGFILE
cd $ORG_PWD
return $SCRIPT_RC
shell-script scripting
New contributor
add a comment |
-1
-1
-1
# C A L L C U S T O M E R D E F I N E D P A R A M E T E R S
#----------------------------------------------------------------------------------
cd /ERQ/100/DM/SCRIPTS
. ./DMPR2ERQ_log_interface.env
#----------------------------------------------------------------------------------
# I N T E R N A L S E C T I O N ! ! !
#----------------------------------------------------------------------------------
ORG_PWD=$PWD # save directory where i am
COUNT=0 # actual value for retry logic
DATE=`date +'%y%m%d%H%M%S'` # creating time stamp
HUMAN_DATE=`date +'%d.%m.%Y - %H:%M:%S'` # creating human readable time stamp
TMP_LOGFILE=$LOG_FILE_OUT.$$ # temporary log file with PID
SLEEP_TIME=10 # how long to wait until check of file size
#----------------------------------------------------------------------------------
# S E N D E M A I L O N E R R O R
#----------------------------------------------------------------------------------
SUBJECT="ERROR in script send_DMPR2ERQ_log.sh for Queue $QUEUE"
function error_mail
{
BODY="nDate: $HUMAN_DATE CET
nScript: $ORG_PWD/send_DMPR2ERQ_log.sh
nServer: `hostname`
nnThe following error occured:
n----------------------------
$ERROR_MSG"
echo "$BODY" | mailx -s "$SUBJECT" "$EMAIL_ADDRESS"
}
#----------------------------------------------------------------------------------
# R E T U R N C O D E S
#----------------------------------------------------------------------------------
RC_OK=0 # used in spoolin and spoolout
RC_PARAM_ERR=1 # used in spoolin and spoolout
RC_LOG_ERR=10 # used in spoolin and spoolout
RC_SI_PATH_ERR=11 # used in spoolin
RC_SO_PATH_ERR=12 # used in spoolout
RC_ARCHIVE_PATH_ERR=13 # used in spoolin
RC_ERROR_PATH_ERR=14 # used in spoolin
RC_NO_FILES_ERR=15 # used in spoolin
RC_NO_QMGR_ERR=20 # used in spoolin and spoolout
RC_NO_QUEUE_ERR=21 # used in spoolin and spoolout
RC_NO_MQSERVER_ERR=22 # used in spoolin and spoolout
RC_DPBAT_ERR=100 # used in spoolin and spoolout
RC_NO_FILENAME_ERR=300
RC_FILENAME_ERR=310
#----------------------------------------------------------------------------------
# E R R O R S E C T I O N
#----------------------------------------------------------------------------------
SCRIPT_RC=$RC_OK # init return code
if touch $LOG_FILE_OUT # log file access?
then
echo "n["$DATE"]" > $TMP_LOGFILE
else
echo "ERROR: RC=$RC_LOG_ERR - Can't create $LOG_FILE_OUT"
return $RC_LOG_ERR
fi
VARCHECK=`echo $MHQ_MQMGRNAME | wc -w`
if [ $VARCHECK = "0" ] # Queue Manager defined?
then
echo "ERROR: RC=$RC_NO_QMGR_ERR - Queue Manager not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_NO_QMGR_ERR - Queue Manager not defined!"
SCRIPT_RC=$RC_NO_QMGR_ERR
fi
VARCHECK=`echo $QUEUE | wc -w`
if [ $VARCHECK = "0" ] # Queue defined?
then
echo "ERROR: RC=$RC_NO_QUEUE_ERR - Target Queue not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_NO_QUEUE_ERR - Target Queue not defined"
SCRIPT_RC=$RC_NO_QUEUE_ERR
fi
VARCHECK=`echo $MQSERVER | wc -w`
if [ $VARCHECK = "0" ] # MQ Server connectivity defined?
then
echo "ERROR: RC=$RC_NO_MQSERVER_ERR - Variable MQSERVER not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_NO_MQSERVER_ERR - Variable MQSERVER not defined"
SCRIPT_RC=$RC_NO_MQSERVER_ERR
fi
VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ] # Archive path defined?
then
echo "ERROR: RC=$RC_ARCHIVE_PATH_ERR - Variable ARCHIVE_PATH not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_ARCHIVE_PATH_ERR - Variable ARCHIVE_PATH not defined"
SCRIPT_RC=$RC_ARCHIVE_PATH_ERR
fi
VARCHECK=`echo $ERROR_PATH | wc -w`
if [ $VARCHECK = "0" ] # Error path defined?
then
echo "ERROR: RC=$RC_ERROR_PATH_ERR - Variable ERROR_PATH not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_ERROR_PATH_ERR - Variable ERROR_PATH not defined"
SCRIPT_RC=$RC_ERROR_PATH_ERR
fi
VARCHECK=`echo $SI_PATH | wc -w`
if [ $VARCHECK != "0" ] # parameter SI_PATH defined?
then
cd $SI_PATH
CD_RC=$?
if [ $CD_RC = "0" ]
then
echo "--> Changed to spoolin directory $SI_PATH successfully." >> $TMP_LOGFILE
else
echo "ERROR: RC=$RC_SI_PATH_ERR - could not change to spoolin directory $SI_PATH" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_SI_PATH_ERR - could not change to spoolin directory $SI_PATH"
SCRIPT_RC=$RC_SI_PATH_ERR
fi
else
echo "ERROR: RC=$RC_SI_PATH_ERR - no variable for spoolin directory specified" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_SI_PATH_ERR - no variable for spoolin directory specified"
SCRIPT_RC=$RC_SI_PATH_ERR
fi
#----------------------------------------------------------------------------------
# S P O O L I N
#----------------------------------------------------------------------------------
if [ $SCRIPT_RC -eq "0" ]
then
#----------------------------------------------------------------------------------
# F I L E P O L L I N G
#----------------------------------------------------------------------------------
cd /srv/ERQ_P2M_DUALACCESS/DM/LOG
cp `ls -tr DMPR2ERP* | tail -1` /ERQ/100/DM/OUTBOUND
cd /ERQ/100/DM/OUTBOUND
for FILE in `ls -l DMPR2ERP*`; do
if [ -f $FILE ]; then
FILE_SIZE_1=`ls -l $FILE | awk '{ printf("%s.%sn", $9, $5) }'`
sleep $SLEEP_TIME
FILE_SIZE_2=`ls -l $FILE | awk '{ printf("%s.%sn", $9, $5) }'`
if [ $FILE_SIZE_1 = $FILE_SIZE_2 ]; then
SI_FILENAME=$FILE
echo " > Putting file $SI_PATH/$SI_FILENAME to Queue $QUEUE" >> $TMP_LOGFILE
#----------------------------------------------------------------------------------
# D E T E R M I N E S P O O L I N O P T I O N
#----------------------------------------------------------------------------------
SI_CMD="si(si-id=$QUEUE, si-filename=$SI_FILENAME); end; "
DPBAT_RC=0
echo $SI_CMD | $MHQ_HOME/dpbat >> $TMP_LOGFILE 2>&1
DPBAT_RC=$?
echo "Return Code (RC) DPBAT = $DPBAT_RC" >> $TMP_LOGFILE
if [ $DPBAT_RC = "0" ]
then
#----------------------------------------------------------------------------
# if RC=0 the spool-in was succesful, move to archive directory
#----------------------------------------------------------------------------
echo "--> File $SI_PATH/$SI_FILENAME successfully put to Queue $QUEUE." >> $TMP_LOGFILE
mv $SI_PATH/$SI_FILENAME $ARCHIVE_PATH
echo "--> File $SI_PATH/$SI_FILENAME moved to archive directory. n " >> $TMP_LOGFILE
else
#----------------------------------------------------------------------------
# if RC<>0 the spool-in was NOT succesful, move to error directory
#----------------------------------------------------------------------------
SCRIPT_RC=`expr $DPBAT_RC + $RC_DPBAT_ERR` # some dpbat errors found!
echo "--> Ended without putting file to Queue. (RC DPBAT: $DPBAT_RC)" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nEnded without putting file to Queue. (RC DPBAT: $DPBAT_RC)"
mv $SI_PATH/$SI_FILENAME $ERROR_PATH
echo "--> Moved file to error directory $ERROR_PATH." >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nMoved file to error directory $ERROR_PATH."
fi
fi
fi
done
else
echo "File $FILE does not exists" >> $TMP_LOGFILE
SCRIPT_RC=15
fi
#----------------------------------------------------------------------------------
# Analyze global error return code and send email if necessary
#----------------------------------------------------------------------------------
if [ $SCRIPT_RC -ne "0" ]
then
echo "ERROR occured. (RC SCRIPT: $SCRIPT_RC)" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR occurred. (RC SCRIPT: $SCRIPT_RC)"
if [ $ERROR_NOTIFICATION = "y" ]
then
echo "Notification sent to $EMAIL_ADDRESS" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nNotification sent to $EMAIL_ADDRESS"
error_mail
fi
fi
#----------------------------------------------------------------------------------
# Append temporary log to main log and delete temporary log file
#----------------------------------------------------------------------------------
cat $TMP_LOGFILE >> $LOG_FILE_OUT
rm -f $TMP_LOGFILE
cd $ORG_PWD
return $SCRIPT_RC
shell-script scripting
New contributor
# C A L L C U S T O M E R D E F I N E D P A R A M E T E R S
#----------------------------------------------------------------------------------
cd /ERQ/100/DM/SCRIPTS
. ./DMPR2ERQ_log_interface.env
#----------------------------------------------------------------------------------
# I N T E R N A L S E C T I O N ! ! !
#----------------------------------------------------------------------------------
ORG_PWD=$PWD # save directory where i am
COUNT=0 # actual value for retry logic
DATE=`date +'%y%m%d%H%M%S'` # creating time stamp
HUMAN_DATE=`date +'%d.%m.%Y - %H:%M:%S'` # creating human readable time stamp
TMP_LOGFILE=$LOG_FILE_OUT.$$ # temporary log file with PID
SLEEP_TIME=10 # how long to wait until check of file size
#----------------------------------------------------------------------------------
# S E N D E M A I L O N E R R O R
#----------------------------------------------------------------------------------
SUBJECT="ERROR in script send_DMPR2ERQ_log.sh for Queue $QUEUE"
function error_mail
{
BODY="nDate: $HUMAN_DATE CET
nScript: $ORG_PWD/send_DMPR2ERQ_log.sh
nServer: `hostname`
nnThe following error occured:
n----------------------------
$ERROR_MSG"
echo "$BODY" | mailx -s "$SUBJECT" "$EMAIL_ADDRESS"
}
#----------------------------------------------------------------------------------
# R E T U R N C O D E S
#----------------------------------------------------------------------------------
RC_OK=0 # used in spoolin and spoolout
RC_PARAM_ERR=1 # used in spoolin and spoolout
RC_LOG_ERR=10 # used in spoolin and spoolout
RC_SI_PATH_ERR=11 # used in spoolin
RC_SO_PATH_ERR=12 # used in spoolout
RC_ARCHIVE_PATH_ERR=13 # used in spoolin
RC_ERROR_PATH_ERR=14 # used in spoolin
RC_NO_FILES_ERR=15 # used in spoolin
RC_NO_QMGR_ERR=20 # used in spoolin and spoolout
RC_NO_QUEUE_ERR=21 # used in spoolin and spoolout
RC_NO_MQSERVER_ERR=22 # used in spoolin and spoolout
RC_DPBAT_ERR=100 # used in spoolin and spoolout
RC_NO_FILENAME_ERR=300
RC_FILENAME_ERR=310
#----------------------------------------------------------------------------------
# E R R O R S E C T I O N
#----------------------------------------------------------------------------------
SCRIPT_RC=$RC_OK # init return code
if touch $LOG_FILE_OUT # log file access?
then
echo "n["$DATE"]" > $TMP_LOGFILE
else
echo "ERROR: RC=$RC_LOG_ERR - Can't create $LOG_FILE_OUT"
return $RC_LOG_ERR
fi
VARCHECK=`echo $MHQ_MQMGRNAME | wc -w`
if [ $VARCHECK = "0" ] # Queue Manager defined?
then
echo "ERROR: RC=$RC_NO_QMGR_ERR - Queue Manager not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_NO_QMGR_ERR - Queue Manager not defined!"
SCRIPT_RC=$RC_NO_QMGR_ERR
fi
VARCHECK=`echo $QUEUE | wc -w`
if [ $VARCHECK = "0" ] # Queue defined?
then
echo "ERROR: RC=$RC_NO_QUEUE_ERR - Target Queue not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_NO_QUEUE_ERR - Target Queue not defined"
SCRIPT_RC=$RC_NO_QUEUE_ERR
fi
VARCHECK=`echo $MQSERVER | wc -w`
if [ $VARCHECK = "0" ] # MQ Server connectivity defined?
then
echo "ERROR: RC=$RC_NO_MQSERVER_ERR - Variable MQSERVER not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_NO_MQSERVER_ERR - Variable MQSERVER not defined"
SCRIPT_RC=$RC_NO_MQSERVER_ERR
fi
VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ] # Archive path defined?
then
echo "ERROR: RC=$RC_ARCHIVE_PATH_ERR - Variable ARCHIVE_PATH not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_ARCHIVE_PATH_ERR - Variable ARCHIVE_PATH not defined"
SCRIPT_RC=$RC_ARCHIVE_PATH_ERR
fi
VARCHECK=`echo $ERROR_PATH | wc -w`
if [ $VARCHECK = "0" ] # Error path defined?
then
echo "ERROR: RC=$RC_ERROR_PATH_ERR - Variable ERROR_PATH not defined" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_ERROR_PATH_ERR - Variable ERROR_PATH not defined"
SCRIPT_RC=$RC_ERROR_PATH_ERR
fi
VARCHECK=`echo $SI_PATH | wc -w`
if [ $VARCHECK != "0" ] # parameter SI_PATH defined?
then
cd $SI_PATH
CD_RC=$?
if [ $CD_RC = "0" ]
then
echo "--> Changed to spoolin directory $SI_PATH successfully." >> $TMP_LOGFILE
else
echo "ERROR: RC=$RC_SI_PATH_ERR - could not change to spoolin directory $SI_PATH" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_SI_PATH_ERR - could not change to spoolin directory $SI_PATH"
SCRIPT_RC=$RC_SI_PATH_ERR
fi
else
echo "ERROR: RC=$RC_SI_PATH_ERR - no variable for spoolin directory specified" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR: RC=$RC_SI_PATH_ERR - no variable for spoolin directory specified"
SCRIPT_RC=$RC_SI_PATH_ERR
fi
#----------------------------------------------------------------------------------
# S P O O L I N
#----------------------------------------------------------------------------------
if [ $SCRIPT_RC -eq "0" ]
then
#----------------------------------------------------------------------------------
# F I L E P O L L I N G
#----------------------------------------------------------------------------------
cd /srv/ERQ_P2M_DUALACCESS/DM/LOG
cp `ls -tr DMPR2ERP* | tail -1` /ERQ/100/DM/OUTBOUND
cd /ERQ/100/DM/OUTBOUND
for FILE in `ls -l DMPR2ERP*`; do
if [ -f $FILE ]; then
FILE_SIZE_1=`ls -l $FILE | awk '{ printf("%s.%sn", $9, $5) }'`
sleep $SLEEP_TIME
FILE_SIZE_2=`ls -l $FILE | awk '{ printf("%s.%sn", $9, $5) }'`
if [ $FILE_SIZE_1 = $FILE_SIZE_2 ]; then
SI_FILENAME=$FILE
echo " > Putting file $SI_PATH/$SI_FILENAME to Queue $QUEUE" >> $TMP_LOGFILE
#----------------------------------------------------------------------------------
# D E T E R M I N E S P O O L I N O P T I O N
#----------------------------------------------------------------------------------
SI_CMD="si(si-id=$QUEUE, si-filename=$SI_FILENAME); end; "
DPBAT_RC=0
echo $SI_CMD | $MHQ_HOME/dpbat >> $TMP_LOGFILE 2>&1
DPBAT_RC=$?
echo "Return Code (RC) DPBAT = $DPBAT_RC" >> $TMP_LOGFILE
if [ $DPBAT_RC = "0" ]
then
#----------------------------------------------------------------------------
# if RC=0 the spool-in was succesful, move to archive directory
#----------------------------------------------------------------------------
echo "--> File $SI_PATH/$SI_FILENAME successfully put to Queue $QUEUE." >> $TMP_LOGFILE
mv $SI_PATH/$SI_FILENAME $ARCHIVE_PATH
echo "--> File $SI_PATH/$SI_FILENAME moved to archive directory. n " >> $TMP_LOGFILE
else
#----------------------------------------------------------------------------
# if RC<>0 the spool-in was NOT succesful, move to error directory
#----------------------------------------------------------------------------
SCRIPT_RC=`expr $DPBAT_RC + $RC_DPBAT_ERR` # some dpbat errors found!
echo "--> Ended without putting file to Queue. (RC DPBAT: $DPBAT_RC)" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nEnded without putting file to Queue. (RC DPBAT: $DPBAT_RC)"
mv $SI_PATH/$SI_FILENAME $ERROR_PATH
echo "--> Moved file to error directory $ERROR_PATH." >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nMoved file to error directory $ERROR_PATH."
fi
fi
fi
done
else
echo "File $FILE does not exists" >> $TMP_LOGFILE
SCRIPT_RC=15
fi
#----------------------------------------------------------------------------------
# Analyze global error return code and send email if necessary
#----------------------------------------------------------------------------------
if [ $SCRIPT_RC -ne "0" ]
then
echo "ERROR occured. (RC SCRIPT: $SCRIPT_RC)" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nERROR occurred. (RC SCRIPT: $SCRIPT_RC)"
if [ $ERROR_NOTIFICATION = "y" ]
then
echo "Notification sent to $EMAIL_ADDRESS" >> $TMP_LOGFILE
ERROR_MSG=$ERROR_MSG"nNotification sent to $EMAIL_ADDRESS"
error_mail
fi
fi
#----------------------------------------------------------------------------------
# Append temporary log to main log and delete temporary log file
#----------------------------------------------------------------------------------
cat $TMP_LOGFILE >> $LOG_FILE_OUT
rm -f $TMP_LOGFILE
cd $ORG_PWD
return $SCRIPT_RC
shell-script scripting
shell-script scripting
New contributor
New contributor
edited 9 mins ago
Michael Homer
48.7k8130168
48.7k8130168
New contributor
asked 18 mins ago
bhavna patilbhavna patil
1
1
New contributor
New contributor
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
bhavna patil is a new contributor. Be nice, and check out our Code of Conduct.
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502236%2fline-220-return-can-can-only-return-from-a-function-or-sourced-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
bhavna patil is a new contributor. Be nice, and check out our Code of Conduct.
draft saved
draft discarded
bhavna patil is a new contributor. Be nice, and check out our Code of Conduct.
bhavna patil is a new contributor. Be nice, and check out our Code of Conduct.
bhavna patil is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502236%2fline-220-return-can-can-only-return-from-a-function-or-sourced-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown