Solved

Help Running a Script

Posted on 2011-03-09
7
288 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:anshuma
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:simon3270
Comment Utility
ETL_ENV is not defined.  Try changing line 59 to:

if [ "$ETL_ENV" = dev ]; then
0
 
LVL 19

Expert Comment

by:simon3270
Comment Utility
Also, on line 71, change:
        if [$? != 0 ]

to
        if [ $? != 0 ]
(space before the "$")
0
 

Author Comment

by:anshuma
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 19

Expert Comment

by:simon3270
Comment Utility
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
 

Author Comment

by:anshuma
Comment Utility
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
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:anshuma
Comment Utility
I am so sorry for my late reply. Thank you very much for this
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now