Help Running a Script

Hi,

I am unable to run this script. I am getting the following error ( I am running it in bash shell) on red hat linux. Please help also I am new to shell scripting can someone help me by explaining this as well


 ksh alpha.sh "a@b.com" "success"

+ LOG_FILE_NAME=Trigger_IMK_PRM_REPORT
+ WGET_COMMAND='http://server/cgi-bin/dl-cmmgr-mstr.cgi?grp=PRMREFRESH&t=1'
+ JOB_ENV=''
+ export JOB_ENV
+ SUBJECT_AREA=''
+ export SUBJECT_AREA
+ MSTR_REFRESH_LOG_FILE=///Trigger_IMK_PRM_REPORT
+ date +%Y%m%d-%H%M
+ MSTR_REFRESH_LOG=///Trigger_IMK_PRM_REPORT.20110309-1236.log
+ [ = dev ]
alpha.sh[59]: [: argument expected
+ echo 'WARNING: Wget command execution is skipped in '
+ 1>> ///Trigger_IMK_PRM_REPORT.20110309-1236.log
+ uname -n
+ MAIL_MSG='sjdimdmsi04: WGET command execution Failed. donot execute on .'
+ EMAIL_SUBJECT='Project PRM analytics Events: WGET command execution Failed'
+ mailx -s 'Project PRM analytics Events: WGET command execution Failed' ''
+ echo ''
+ exit 7


#!/bin/ksh
#-------------------------------------------------------------------------------------------
#
# Execution:    alpha.ksh
#
# Usage :             $ ksh alpha.ksh to_email_address
#
# Parameters:   
#                ALERT_EMAIL_TO_LIST   -- Contains Emailids to which the alerts have to be sent 
#                SUBJECT               -- Contains the subject of the email   
#
#-------------------------------------------------------------------------------------------

set -x
  LOG_FILE_NAME=Trigger_IMK_PRM_REPORT
  WGET_COMMAND="http://server/cgi-bin/dl-cmmgr-mstr.cgi?grp=PRMREFRESH&t=1"
  
  export JOB_ENV=$JOB_ENV
  export SUBJECT_AREA=${ETL_ID%%.*}
  
  MSTR_REFRESH_LOG_FILE=${DW_LOG}/${JOB_ENV}/${SUBJECT_AREA}/${LOG_FILE_NAME};
  MSTR_REFRESH_LOG=${DW_LOG}/${JOB_ENV}/${SUBJECT_AREA}/${LOG_FILE_NAME}.`date '+%Y%m%d-%H%M'`.log;
  
trigger_mstr_report()
{                              
                                set -x;
                                                                
                                #Execute the Wget command on the command prompt and capture the connection status"
        `exec /usr/local/bin/wget ${WGET_COMMAND} > $MSTR_REFRESH_LOG 2>&1 `
        sleep 30;
        echo "-----------+-----------+------------+------------+-----------+--" >> $MSTR_REFRESH_LOG    
                                
                                #Copy the contents of the file to log that just got downloaded and delete it
         if [ -f dl-cmmgr-mstr.cgi?grp*PRMREFRESH* ]; then
           cat dl-cmmgr-mstr.cgi?grp*PRMREFRESH* >> $MSTR_REFRESH_LOG
        fi
                                
                                #check if the connection was success and the response was recived
                                EMAIL_GROUP=${ALERT_EMAIL_TO_LIST}
                                grep "... connected." ${MSTR_REFRESH_LOG} > /dev/null 2>&1
        CONNECT=$?
        grep "HTTP request sent, awaiting response... 200 OK" ${MSTR_REFRESH_LOG} > /dev/null 2>&1
        RESPONSE=$?
        if [ $CONNECT -ne 0 ] || [ $RESPONSE -ne 0 ]; then
           echo "`uname -n`:  WGET command execution Failed. Please investigate."
           EMAIL_MSG="`uname -n`: WGET command execution Failed. Please investigate. Temporarily, please manually submit WGET command and fix the issue."
           EMAIL_SUBJECT="Project Trtiton analytics Events: WGET command execution Failed"
                                   echo "$EMAIL_MSG" | mailx -s "$EMAIL_SUBJECT" "$EMAIL_GROUP"
                                else
           echo "`uname -n`:  WGET command was executed successfully."
        fi
}

##########
## MAIN ##
##########

# Executing Wget Command
if [ $ETL_ENV = dev ]; then
                                
                                echo `pwd` >> $MSTR_REFRESH_LOG 
                                # Deleting the files in $LOG which are older than 7 days
        find ${MSTR_REFRESH_LOG_FILE}*log -mtime +"7" -exec rm -f {} \;
                                
                                ALERT_EMAIL_TO_LIST=${1##*=}
                                trigger_mstr_report;
                                
                                rm -f dl-cmmgr-mstr.cgi?grp*PRMREFRESH*;

                                echo "Wget command is being executed from $ETL_ENV on : `uname -n`." >> $MSTR_REFRESH_LOG;
        if [$? != 0 ] 
           then echo "\n ${0##*/}:  ERROR : $?"
                echo "failed to run wget command"
         exit 7
           else         
                  echo "\n ${0##*/}:  INFO  : wget command ran sucessfully"
      fi
else
   echo "WARNING: Wget command execution is skipped in $ETL_ENV" >> $MSTR_REFRESH_LOG;
                MAIL_MSG="`uname -n`: WGET command execution Failed. donot execute on $ETL_ENV."
    EMAIL_SUBJECT="Project PRM analytics Events: WGET command execution Failed"
                echo "$EMAIL_MSG" | mailx -s "$EMAIL_SUBJECT" "$EMAIL_GROUP"
   exit 7
fi

Open in new window

anshumaEngineeringAsked:
Who is Participating?
 
simon3270Commented:
There are no shell error messages in your most recent output, so the script is a valid shell script.  Whether it is doing what you want it to do is a different question!

I don't know why the script is testing that $ETL_ENV is dev.  My guess is that you are only supposed to run this script in certain environments, or only after certain other scripts have run.  $ETL_ENV will be set to dev in those environments (possibly in the .profile startup script of some users, or as part of another script).

I'm also a bit surprised at the "if [$? != 0 ]" test on line 71.  It claims to be testing whether the wget command worked, but what it is actually doing is testing whether the "echo" on the previous line worked.  If you want to log the wget success in this way, you will have to set a variable in the trigger_mstr_report function.  For example, have:
    if [ $CONNECT -ne 0 ] || [ $RESPONSE -ne 0 ]; then
           echo "`uname -n`:  WGET command execution Failed. Please investigate."
           EMAIL_MSG="`uname -n`: WGET command execution Failed. Please investigate. Temporarily, please manually submit WGET command and fix the issue."
           EMAIL_SUBJECT="Project Trtiton analytics Events: WGET command execution Failed"
           echo "$EMAIL_MSG" | mailx -s "$EMAIL_SUBJECT" "$EMAIL_GROUP"
           wgetok=1
       else
           echo "`uname -n`:  WGET command was executed successfully."
           wgetok=0
       fi

Open in new window

Then line 71 is replaced by
if [ $wgetok != 0 ]

Open in new window



0
 
simon3270Commented:
ETL_ENV is not defined.  Try changing line 59 to:

if [ "$ETL_ENV" = dev ]; then
0
 
simon3270Commented:
Also, on line 71, change:
        if [$? != 0 ]

to
        if [ $? != 0 ]
(space before the "$")
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
anshumaEngineeringAuthor Commented:
I made the changes now I get the following

+ [ '' = dev ]
+ echo 'WARNING: Wget command execution is skipped in '
+ 1>> ///Trigger_IMK_PRM_REPORT.20110309-1342.log
+ uname -n
+ MAIL_MSG='sjdimdmsi04: WGET command execution Failed. donot execute on .'
+ EMAIL_SUBJECT='Project PRM analytics Events: WGET command execution Failed'
+ mailx -s 'Project PRM analytics Events: WGET command execution Failed' ''
+ echo ''
+ exit 7
0
 
simon3270Commented:
So the script is now working, but ETL_ENV is not defined.  Do you need to have

    ETL_ENV=dev

before you run the script?
0
 
anshumaEngineeringAuthor Commented:
I am not sure, Could you please tell me how do you know that the script is working  ? also could you explain why are we doing this

if [ "$ETL_ENV" = dev ]; then

Sorry for bugging you but I am getting started with this
0
 
anshumaEngineeringAuthor Commented:
I am so sorry for my late reply. Thank you very much for this
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.