Solved

Help Running a Script

Posted on 2011-03-09
7
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:simon3270
ID: 35087717
ETL_ENV is not defined.  Try changing line 59 to:

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

Expert Comment

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

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

Author Comment

by:anshuma
ID: 35088142
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 19

Expert Comment

by:simon3270
ID: 35088419
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
ID: 35088631
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
ID: 35092833
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
ID: 35144368
I am so sorry for my late reply. Thank you very much for this
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Utilizing an array to gracefully append to a list of EmailAddresses
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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