Amit
asked on
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=///T rigger_IMK _PRM_REPOR T
+ date +%Y%m%d-%H%M
+ MSTR_REFRESH_LOG=///Trigge r_IMK_PRM_ REPORT.201 10309-1236 .log
+ [ = dev ]
alpha.sh[59]: [: argument expected
+ echo 'WARNING: Wget command execution is skipped in '
+ 1>> ///Trigger_IMK_PRM_REPORT. 20110309-1 236.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
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_
+ 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=///T
+ date +%Y%m%d-%H%M
+ MSTR_REFRESH_LOG=///Trigge
+ [ = dev ]
alpha.sh[59]: [: argument expected
+ echo 'WARNING: Wget command execution is skipped in '
+ 1>> ///Trigger_IMK_PRM_REPORT.
+ 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
Also, on line 71, change:
if [$? != 0 ]
to
if [ $? != 0 ]
(space before the "$")
if [$? != 0 ]
to
if [ $? != 0 ]
(space before the "$")
ASKER
I made the changes now I get the following
+ [ '' = dev ]
+ echo 'WARNING: Wget command execution is skipped in '
+ 1>> ///Trigger_IMK_PRM_REPORT. 20110309-1 342.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
+ [ '' = dev ]
+ echo 'WARNING: Wget command execution is skipped in '
+ 1>> ///Trigger_IMK_PRM_REPORT.
+ 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
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?
ETL_ENV=dev
before you run the script?
ASKER
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
if [ "$ETL_ENV" = dev ]; then
Sorry for bugging you but I am getting started with this
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am so sorry for my late reply. Thank you very much for this
if [ "$ETL_ENV" = dev ]; then