line 220 : return: can can only 'return' from a function or sourced script [closed]












-4

















# 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









share|improve this question















closed as unclear what you're asking by Thomas, Jeff Schaller, Michael Homer, jimmij, ilkkachu Feb 24 at 15:02


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 1





    This is a difficult one! 1.) What ist the question 2.) Where is line 220 ?

    – gerhard d.
    Feb 22 at 7:25











  • the last line in script "return $SCRIPT_RC".

    – bhavna patil
    Feb 22 at 8:32






  • 1





    Possible duplicate of Return value error in bash scripts

    – Thomas
    Feb 23 at 9:50
















-4

















# 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









share|improve this question















closed as unclear what you're asking by Thomas, Jeff Schaller, Michael Homer, jimmij, ilkkachu Feb 24 at 15:02


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 1





    This is a difficult one! 1.) What ist the question 2.) Where is line 220 ?

    – gerhard d.
    Feb 22 at 7:25











  • the last line in script "return $SCRIPT_RC".

    – bhavna patil
    Feb 22 at 8:32






  • 1





    Possible duplicate of Return value error in bash scripts

    – Thomas
    Feb 23 at 9:50














-4












-4








-4










# 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









share|improve this question


















# 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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 22 at 7:14









Michael Homer

49.7k8134174




49.7k8134174










asked Feb 22 at 7:05









bhavna patilbhavna patil

1




1




closed as unclear what you're asking by Thomas, Jeff Schaller, Michael Homer, jimmij, ilkkachu Feb 24 at 15:02


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by Thomas, Jeff Schaller, Michael Homer, jimmij, ilkkachu Feb 24 at 15:02


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1





    This is a difficult one! 1.) What ist the question 2.) Where is line 220 ?

    – gerhard d.
    Feb 22 at 7:25











  • the last line in script "return $SCRIPT_RC".

    – bhavna patil
    Feb 22 at 8:32






  • 1





    Possible duplicate of Return value error in bash scripts

    – Thomas
    Feb 23 at 9:50














  • 1





    This is a difficult one! 1.) What ist the question 2.) Where is line 220 ?

    – gerhard d.
    Feb 22 at 7:25











  • the last line in script "return $SCRIPT_RC".

    – bhavna patil
    Feb 22 at 8:32






  • 1





    Possible duplicate of Return value error in bash scripts

    – Thomas
    Feb 23 at 9:50








1




1





This is a difficult one! 1.) What ist the question 2.) Where is line 220 ?

– gerhard d.
Feb 22 at 7:25





This is a difficult one! 1.) What ist the question 2.) Where is line 220 ?

– gerhard d.
Feb 22 at 7:25













the last line in script "return $SCRIPT_RC".

– bhavna patil
Feb 22 at 8:32





the last line in script "return $SCRIPT_RC".

– bhavna patil
Feb 22 at 8:32




1




1





Possible duplicate of Return value error in bash scripts

– Thomas
Feb 23 at 9:50





Possible duplicate of Return value error in bash scripts

– Thomas
Feb 23 at 9:50










1 Answer
1






active

oldest

votes


















1














Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-scripts are very similar in that respect.



The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.



It may well be that your script is supposed to be executed as



. ./script.sh


rather than as



./script.sh


or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).



Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does



VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]


This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS). In fact, more than half the script is taken up by statements verifying configuration settings.



Instead, one could use



if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]


or, in bash,



if [ ! -v ARCHIVE_PATH ]


or, if you just want to test for an empty value,



if [ -z "$ARCHIVE_PATH" ]


The script also uses ls in multiple places to get lists of files, which is less than ideal.






share|improve this answer


























  • The script gives the above error when it is executed through SM69 whereas when it is executed as './script.sh' it works fine . Is there any other option to remove this error in SM69?

    – bhavna patil
    Feb 22 at 8:37













  • Both return statements (return $RC_LOG_ERR and return $SCRIPT_RC) should result in an error "./script.sh: line xy: return: can only `return' from a function or sourced script" when executed as script.

    – Freddy
    Feb 22 at 8:43











  • @bhavnapatil I don't know how SM69 executes the script or what shell it uses to execute the script. Some shells would probably be ok with executing it as ./script.sh but as I don't even know what SM69 is I can't say anything about it. There is no indication as to what shell is being used here.

    – Kusalananda
    Feb 22 at 8:43








  • 1





    @bhavnapatil Also, you should never ever "enable options to remove errors"!! Errors are removed by writing correct code.

    – Kusalananda
    Feb 22 at 8:46











  • @Kusalananda Ok got it.

    – bhavna patil
    Feb 25 at 6:20


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-scripts are very similar in that respect.



The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.



It may well be that your script is supposed to be executed as



. ./script.sh


rather than as



./script.sh


or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).



Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does



VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]


This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS). In fact, more than half the script is taken up by statements verifying configuration settings.



Instead, one could use



if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]


or, in bash,



if [ ! -v ARCHIVE_PATH ]


or, if you just want to test for an empty value,



if [ -z "$ARCHIVE_PATH" ]


The script also uses ls in multiple places to get lists of files, which is less than ideal.






share|improve this answer


























  • The script gives the above error when it is executed through SM69 whereas when it is executed as './script.sh' it works fine . Is there any other option to remove this error in SM69?

    – bhavna patil
    Feb 22 at 8:37













  • Both return statements (return $RC_LOG_ERR and return $SCRIPT_RC) should result in an error "./script.sh: line xy: return: can only `return' from a function or sourced script" when executed as script.

    – Freddy
    Feb 22 at 8:43











  • @bhavnapatil I don't know how SM69 executes the script or what shell it uses to execute the script. Some shells would probably be ok with executing it as ./script.sh but as I don't even know what SM69 is I can't say anything about it. There is no indication as to what shell is being used here.

    – Kusalananda
    Feb 22 at 8:43








  • 1





    @bhavnapatil Also, you should never ever "enable options to remove errors"!! Errors are removed by writing correct code.

    – Kusalananda
    Feb 22 at 8:46











  • @Kusalananda Ok got it.

    – bhavna patil
    Feb 25 at 6:20
















1














Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-scripts are very similar in that respect.



The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.



It may well be that your script is supposed to be executed as



. ./script.sh


rather than as



./script.sh


or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).



Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does



VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]


This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS). In fact, more than half the script is taken up by statements verifying configuration settings.



Instead, one could use



if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]


or, in bash,



if [ ! -v ARCHIVE_PATH ]


or, if you just want to test for an empty value,



if [ -z "$ARCHIVE_PATH" ]


The script also uses ls in multiple places to get lists of files, which is less than ideal.






share|improve this answer


























  • The script gives the above error when it is executed through SM69 whereas when it is executed as './script.sh' it works fine . Is there any other option to remove this error in SM69?

    – bhavna patil
    Feb 22 at 8:37













  • Both return statements (return $RC_LOG_ERR and return $SCRIPT_RC) should result in an error "./script.sh: line xy: return: can only `return' from a function or sourced script" when executed as script.

    – Freddy
    Feb 22 at 8:43











  • @bhavnapatil I don't know how SM69 executes the script or what shell it uses to execute the script. Some shells would probably be ok with executing it as ./script.sh but as I don't even know what SM69 is I can't say anything about it. There is no indication as to what shell is being used here.

    – Kusalananda
    Feb 22 at 8:43








  • 1





    @bhavnapatil Also, you should never ever "enable options to remove errors"!! Errors are removed by writing correct code.

    – Kusalananda
    Feb 22 at 8:46











  • @Kusalananda Ok got it.

    – bhavna patil
    Feb 25 at 6:20














1












1








1







Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-scripts are very similar in that respect.



The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.



It may well be that your script is supposed to be executed as



. ./script.sh


rather than as



./script.sh


or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).



Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does



VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]


This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS). In fact, more than half the script is taken up by statements verifying configuration settings.



Instead, one could use



if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]


or, in bash,



if [ ! -v ARCHIVE_PATH ]


or, if you just want to test for an empty value,



if [ -z "$ARCHIVE_PATH" ]


The script also uses ls in multiple places to get lists of files, which is less than ideal.






share|improve this answer















Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-scripts are very similar in that respect.



The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.



It may well be that your script is supposed to be executed as



. ./script.sh


rather than as



./script.sh


or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).



Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does



VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]


This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS). In fact, more than half the script is taken up by statements verifying configuration settings.



Instead, one could use



if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]


or, in bash,



if [ ! -v ARCHIVE_PATH ]


or, if you just want to test for an empty value,



if [ -z "$ARCHIVE_PATH" ]


The script also uses ls in multiple places to get lists of files, which is less than ideal.







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 22 at 8:32

























answered Feb 22 at 7:34









KusalanandaKusalananda

135k17255421




135k17255421













  • The script gives the above error when it is executed through SM69 whereas when it is executed as './script.sh' it works fine . Is there any other option to remove this error in SM69?

    – bhavna patil
    Feb 22 at 8:37













  • Both return statements (return $RC_LOG_ERR and return $SCRIPT_RC) should result in an error "./script.sh: line xy: return: can only `return' from a function or sourced script" when executed as script.

    – Freddy
    Feb 22 at 8:43











  • @bhavnapatil I don't know how SM69 executes the script or what shell it uses to execute the script. Some shells would probably be ok with executing it as ./script.sh but as I don't even know what SM69 is I can't say anything about it. There is no indication as to what shell is being used here.

    – Kusalananda
    Feb 22 at 8:43








  • 1





    @bhavnapatil Also, you should never ever "enable options to remove errors"!! Errors are removed by writing correct code.

    – Kusalananda
    Feb 22 at 8:46











  • @Kusalananda Ok got it.

    – bhavna patil
    Feb 25 at 6:20



















  • The script gives the above error when it is executed through SM69 whereas when it is executed as './script.sh' it works fine . Is there any other option to remove this error in SM69?

    – bhavna patil
    Feb 22 at 8:37













  • Both return statements (return $RC_LOG_ERR and return $SCRIPT_RC) should result in an error "./script.sh: line xy: return: can only `return' from a function or sourced script" when executed as script.

    – Freddy
    Feb 22 at 8:43











  • @bhavnapatil I don't know how SM69 executes the script or what shell it uses to execute the script. Some shells would probably be ok with executing it as ./script.sh but as I don't even know what SM69 is I can't say anything about it. There is no indication as to what shell is being used here.

    – Kusalananda
    Feb 22 at 8:43








  • 1





    @bhavnapatil Also, you should never ever "enable options to remove errors"!! Errors are removed by writing correct code.

    – Kusalananda
    Feb 22 at 8:46











  • @Kusalananda Ok got it.

    – bhavna patil
    Feb 25 at 6:20

















The script gives the above error when it is executed through SM69 whereas when it is executed as './script.sh' it works fine . Is there any other option to remove this error in SM69?

– bhavna patil
Feb 22 at 8:37







The script gives the above error when it is executed through SM69 whereas when it is executed as './script.sh' it works fine . Is there any other option to remove this error in SM69?

– bhavna patil
Feb 22 at 8:37















Both return statements (return $RC_LOG_ERR and return $SCRIPT_RC) should result in an error "./script.sh: line xy: return: can only `return' from a function or sourced script" when executed as script.

– Freddy
Feb 22 at 8:43





Both return statements (return $RC_LOG_ERR and return $SCRIPT_RC) should result in an error "./script.sh: line xy: return: can only `return' from a function or sourced script" when executed as script.

– Freddy
Feb 22 at 8:43













@bhavnapatil I don't know how SM69 executes the script or what shell it uses to execute the script. Some shells would probably be ok with executing it as ./script.sh but as I don't even know what SM69 is I can't say anything about it. There is no indication as to what shell is being used here.

– Kusalananda
Feb 22 at 8:43







@bhavnapatil I don't know how SM69 executes the script or what shell it uses to execute the script. Some shells would probably be ok with executing it as ./script.sh but as I don't even know what SM69 is I can't say anything about it. There is no indication as to what shell is being used here.

– Kusalananda
Feb 22 at 8:43






1




1





@bhavnapatil Also, you should never ever "enable options to remove errors"!! Errors are removed by writing correct code.

– Kusalananda
Feb 22 at 8:46





@bhavnapatil Also, you should never ever "enable options to remove errors"!! Errors are removed by writing correct code.

– Kusalananda
Feb 22 at 8:46













@Kusalananda Ok got it.

– bhavna patil
Feb 25 at 6:20





@Kusalananda Ok got it.

– bhavna patil
Feb 25 at 6:20



Popular posts from this blog

How to make a Squid Proxy server?

第一次世界大戦

Touch on Surface Book