05-14-2014
Issue with script
Hi,
I have a script which when i run in manually it runs properly, but when i run the same script using UC4 scheduler it dose not run properly.
Below is the code i am using. i am not sure what is happening when i run this through UC4 the files are not generated. but when i run this manually it works fine.
Code:
## The below path is defined for config file.
. /****/****/****/****/****/****/.config_****.env
## Below variables are populated from the config file defined above.
DBUSER=$DBUSR
DBPASS=$DBPWD
SYSID=$SYSTEMID
tgtpath=$path
tablenamepath=$Tablenamefilepath
TABLE_FILE=$Table_NAME_EXTERNALID
logfile=$errorlog
Emailuser_BE=$Emailuser_BE
Emailuser_NL=$Emailuser_NL
Emailuser_DK=$Emailuser_DK
zippath=$zippath
logfiledirectory=$log_dir
## Below variable is assigned from the argument passed while executing the script.
Countrycode=$1
## Below variables are assigned dynamically as and when the script is called
allfile=FF_ErrorReport_****_$(date +"%Y%m%d%H%M")_${Countrycode}.csv
allfilezip=FF_ErrorReport_****_$(date +"%Y%m%d%H%M")_${Countrycode}.csv.zip
time=$(date +"%Y%m%d%H%M%S")
today=$(date +"%Y%m%d")
if [ $Countrycode == **** ]
then
Emailuser=$Emailuser_****
CountryName=****
elif [ $Countrycode == **** ]
then
Emailuser=$Emailuser_****
CountryName=****
elif [ $Countrycode == **** ]
then
Emailuser=$Emailuser_****
CountryName=****
elif [ $Countrycode == **** ]
then
Emailuser=$Emailuser_****
CountryName=****
elif [ $Countrycode == **** ]
then
Emailuser=$Emailuser_****
CountryName=****
elif [ $Countrycode == **** ]
then
Emailuser=$Emailuser_****
CountryName=****
else
echo 'Please enter country code as either BE, NL or DK these are the country codes present in BENO. If you want to generate the file for any other OPU please contact the L2 support team.'
fi
email_with_attachment ()
{
email_body="
Hi All,\n
\n
**** Code $Countrycode\n
\n
Reject Report File Name:$allfile\n
\n
Execution Time=$time\n
\n
This email is automatically generated. Please do not reply.\n
\n
Best Regards\n
-Integration Team "
(echo -e ${email_body};uuencode $zippath$allfilezip $allfilezip) | mail -s "The $allfile file is generated and mail is sent for $(date +"%Y%m%d") run for $CountryName is successful." $Emailuser
}
## End of email_with_attachment function
email_without_attachment ()
{
email_body="
Hi All,\n
\n
The Target file generated for today's run was more than 10 MB, so it is not attached. Please find the reject report in the following path:\n
\n
Reject Report File Name:$zippath
\n
Reject Report File Name:$allfile\n
\n
Execution Time=$time\n
\n
This email is automatically generated. Please do not reply.\n
\n
Best Regards\n
-Integration Team "
(echo -e ${email_body}) | mail -s "The $allfile file is generated and mail is sent for $(date +"%Y%m%d") run for $CountryName is successful." $Emailuser
}
## End of email_without_attachment function
## The below function is defined to log into the database and get the data according to the sql query.
errorsql ()
{
errorreport=FF_ErrorReport_Veeva
## This function is the InitCap function for unix
firstvalue=`echo $2 | awk -F"\_" '{print $3}' | awk '{print toupper(substr($1,1,1)) tolower(substr($1,2))}'`
secondvalue=`echo $2 | awk -F"\_" '{print $4}' | awk '{print toupper(substr($1,1,1)) tolower(substr($1,2))}'`
thirdvalue=`echo $2 | awk -F"\_" '{print $5}' | awk '{print toupper(substr($1,1,1)) tolower(substr($1,2))}'`
fourthvalue=`echo $2 | awk -F"\_" '{print $6}' | awk '{print toupper(substr($1,1,1)) tolower(substr($1,2))}'`
interfacename="${firstvalue}${secondvalue}${thirdvalue}${fourthvalue}"
tgtfile="${errorreport}_${interfacename}"_Load_$(date +"%Y%m%d%H%M%S")_${Countrycode}_BENO.csv
sqlplus -s $DBUSER/$DBPASS@$SYSID > $logfiledirectory/$logfile << EOF
SET HEADING OFF
SET SERVEROUTPUT ON
SET VERIFY OFF
SET TERMOUT OFF
SET TRIMSPOOL OFF
SET FEEDBACK OFF
SET LINESIZE 5000
WHENEVER SQLERROR EXIT FAILURE;
spool $tgtpath/$tgtfile
SELECT 'EXTERNAL_ID_VOD__C,T_SRC_COUNTRY,T_SRC_SYSTEM,T_REC_ACTION,T_STATUS,T_REC_CREATE_DT,T_ETL_JOB_ID,T_ REC_UPDATE_DT,T_LAYER_INDCTR,T_REJECT_REASON' FROM DUAL;
SELECT $3||','||T_SRC_COUNTRY||','||T_SRC_SYSTEM||','||T_REC_ACTION||','||T_STATUS||','||T_REC_CREATE_DT||' ,'||T_ETL_JOB_ID||','||T_REC_UPDATE_DT||','||T_LAYER_INDCTR||','||T_REJECT_REASON
FROM CRM_ODS_BX.$2
WHERE T_STATUS = 'OPEN'
AND T_LAYER_INDCTR IN ('ODS','VEEVA')
AND T_SRC_COUNTRY = '$1'
AND $3 IS NOT NULL;
spool off
EOF
}
table which ********.
for i in `cat ${tablenamepath}/${TABLE_FILE}`
do
tablename=`echo $i | cut -d "," -f1`
externalid=`echo $i | cut -d "," -f2`
errorsql $Countrycode $tablename $externalid
done
## End of for loop.
zip -9 -r $zippath$allfilezip $tgtpath/FF_ErrorReport_Veeva*$today*_${Countrycode}_BENO.csv
Filesize=`ls -ltr $zippath$allfilezip | cut -d ' ' -f5`
if [ $Filesize -le 10485760 ]
then
email_with_attachment
else
email_without_attachment
fi
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am working on a script that checks two arguments at the command line. The first argument is a search pattern, the second can be a file or a directory, if it is a file a second script is called that checks it for the search pattern. If the second argument is a directory, it checks for the search... (5 Replies)
Discussion started by: Breakology
5 Replies
2. Shell Programming and Scripting
#!/bin/ksh
set -x
SQLSTR="LOGIN/PASSWORD"
sqlplus -s ${SQLSTR} @<<EOF
set pagesize 0 feedback off verify off heading off echo off;
UPDATE TABLE NAME
SET VALUE = VALUE + 1
where VALUE2 = 'ABCDE';
exit;
COMMIT;
EOF
i am not able to update the column and not able to exit from sqlplus. ... (7 Replies)
Discussion started by: karthicss
7 Replies
3. Shell Programming and Scripting
Hello All,
I am ruuning the below script.
userchecking.sh
###########################
#! /bin/ksh
NIS_SCRIPT_HOME="/mot/systems/NIS_SCRIPT_NEW"
. $NIS_SCRIPT_HOME/common.env
WORK_DIR="/mot/systems/scripts/"
#WORK_DIR="/mot/b36376/myscripts/nis_user_automation"... (1 Reply)
Discussion started by: ajaincv
1 Replies
4. Shell Programming and Scripting
#!/bin/bash
###########################################
ADMIN="usera@mblonline.com"
AMQ="userb@mblonline.com"
SUBJECT="Remote Shutdown Client Status"
MAIL="/bin/mail"
###########################################
DAT=`date '+%d-%b-%Y'`
PLUGIN="/usr/lib/nagios/plugins/check_nrpe"
PORT="5666"... (2 Replies)
Discussion started by: telnor
2 Replies
5. Shell Programming and Scripting
#!/bin/ksh
i=1
while
do
j=0
while
do
echo "$i"
j =`expr $j + 1`
done
i=`expr $i + 1`
done (19 Replies)
Discussion started by: targetshell
19 Replies
6. Shell Programming and Scripting
Hi Folks,
I am going through a sample script which is not working.
Also i want to understand the certain syntaxes
#!/bin/sh
clear
x="y"
echo "enter ur 1st no."
read n1
echo "enter ur 2nd no."
read n2
while
do
clear
echo "1.sum"
echo "2.subtraction"
echo "3.product"... (3 Replies)
Discussion started by: rafa_fed2
3 Replies
7. Shell Programming and Scripting
I am trying to run a script which ftp the files from one server to another.
Below is the script -
#!/bin/bash
echo "Please enter no : "
read variable
echo "You entered: $input_variable"
host=xxxxx
USER=xxx
PASSWORD=xxx
ftp -inv $HOST <<EOF
user $USER $PASSWORD
cd... (4 Replies)
Discussion started by: chandraprakash
4 Replies
8. Shell Programming and Scripting
I developed a script to group by 1st column and sum few of the column which are required, but while executing sum of 2nd column which has decimals in place is not getting correct sum. below is the script
awk -F, '{a+=$2;b+=$33;c+=$58;d+=$11;e+=$50;}END{for(i in a)printf... (2 Replies)
Discussion started by: rramkrishnas
2 Replies
9. Shell Programming and Scripting
Hi,
I am running below script using autosys.
Though the script is running fine, it fails the workflow but the autosys job shows success.
Can you please let me know where can i make change to script:-
#!/bin/ksh
#to test mail from directory
set -x
frequency=$1
param_file=/local/test... (4 Replies)
Discussion started by: rajrishi990
4 Replies
10. Shell Programming and Scripting
Hello,
I have the following script that just archives and clears some log files.
#!/bin/bash
# script: archive_logs_and_clear
# add date to logfile names and copy archive directory
# clear logs
# change to script directory
cd ... (4 Replies)
Discussion started by: LMHmedchem
4 Replies