Sponsored Content
Top Forums Shell Programming and Scripting Can't figure out else not matching Post 302089487 by peteroc on Tuesday 19th of September 2006 09:18:24 AM
Old 09-19-2006
Entire Script

#!/bin/ksh

#set -x

# 7/28/06 PEYOUN. This script unzips, decrypts, and FTP's the BAMH file provided by HSBC to the Mainframe for subsequent processing.
#
##
## NOTE: FILE and UNZIP_FILE are only good up until the end of 2009,
## at which time the hard-coded 0 will need to be incremented by 1.
##
DIR=/home/gmcs_team
cd $DIR

YMM=`echo $(date +%y%m) | cut -c 2-4`
((DATA_MONTH=$YMM-1))
##overriding DATA_MONTH because files are old. Still catching up from 0601 data through the present.
##once we're caught up we can remove the override.
DATA_MONTH=602
FILE=`ls AXEM.BM0${DATA_MONTH}OT.zip`
##
##
##
if [[ ! -a ${FILE} ]]; then
echo "BAMH input file does not exist on cwyeta01 yet. Quitting..."
exit 1
fi

LOG_DIR=~/log
cd $LOG_DIR

LOG_NAME="$(basename $0 .ksh)"_$(date +%m%d%Y).log

exec 1>$LOG_NAME
exec 2>&1

Script_Name=$(basename $0)
echo "$Script_Name has been initiated"

echo "LOG_DIR=$LOG_DIR"

ODRIVE=General_Motors/GM_Card/Production/Monthly/HSBC_BAMH/Logs
echo "ODRIVE=$ODRIVE"

echo "FILE=$FILE"
echo "YMM=$YMM"
echo "DIR=$DIR"

DATE=$(date +%m%d%Y)
echo "DATE=$DATE"

DATE2=$(date +%m%d%y)
echo "DATE2=$DATE2"

DSN=BAMH.IN
echo "DSN=$DSN"

PUSER=#####
echo "PUSER=$PUSER"

PPASS=#######

USER=######
echo "User=$USER"

PASS=#######

RECFM=FB
echo "RECFM=$RECFM"

integer LRECL=256
echo "LRECL=$LRECL"

integer BLKSIZE=32512
echo "BLKSIZE=$BLKSIZE"

UNIT=ACS2
echo "UNIT=$UNIT"

integer VCOUNT=20
echo "VCOUNT=$VCOUNT"

RETPD=90
echo "RETPD=$RETPD"

FILE_NAME=HSBCemail_${DATE2}_
echo "FILE_NAME=$FILE_NAME"

PROCESS="BAMH"
echo "PROCESS=$PROCESS"

DECRYPT_FILE=${FILE_NAME}${PROCESS}.txt
echo "DECRYPT_FILE=$DECRYPT_FILE"

DIR=/home/gmcs_team
echo "DIR=$DIR"

LOG=/home/gmcs_team/log
echo "LOG=$LOG"

EMAIL_SUPPORT=############@$######.com
echo EMAIL_SUPPORT="$EMAIL_SUPPORT"

# override while debugging
EMAIL_SUPPORT=peyoun@######.com

integer HOLDFILESIZE=0
echo "HOLDFILESIZE=$HOLDFILESIZE"

MFFILE="'ACXI.S08.C01028.F03108.PYU31.${DSN}'"
echo "MFFILE=$MFFILE"

integer FILESIZE=0
echo "FILESIZE=$FILESIZE"

integer DIFF=0
echo "DIFF=$DIFF"

integer I=0
echo "I=$I"

SUBJECT="BAMH Process Log File Created"

MESSAGE="$Script_Name has completed on ########. See ########################################################### for a complete log of this job."

#integer NUMRECS=`ls $FILE | awk -F '_' '{print $7}' | awk -F '.' '{print $1}'` #integer NUMRECS=`ls $FILE | awk -F '_' '{print $7}' | awk -F '.' '{print $1}'`

cd $DIR
# potentially infinite loop!
while :
do

FILESIZE=`ls -l $FILE | awk '{print $5}'`
echo "FILESIZE=$FILESIZE"
(( DIFF = $FILESIZE - $HOLDFILESIZE ))

if (( $DIFF != 0 )); then
(( HOLDFILESIZE=$FILESIZE ))
echo "HOLDFILESIZE=$HOLDFILESIZE"
(( I= $I + 1 ))
echo "I=$I"
if (( $I > 1 ));then
echo "$PROCESS file - $FILE processed by $Script_Name has not been completely FTP'd to ######## ${DIR}. Waiting....."
echo "$PROCESS file - $FILE processed by $Script_Name has not been completely FTP'd to ######## ${DIR}. Waiting....." | mailx -s "$PROCESS file - $FILE has not been completely FTP'd to cwyeta01 $DIR. Waiting 1 minute ....." $EMAIL_SUPPORT
fi

if (($I > 20));then
echo "$PROCESS file - FTP loop for $FILE in script $Script_Name exceeded 20 iterations. Possible infinite loop - breaking"
mailx -s "$PROCESS - FTP loop for $FILE in script $Script_Name exceeded 20 iterations. Possible infinite loop - breaking" $EMAIL_SUPPORT
break
fi

sleep 60
else
echo "$PROCESS file - ${DIR}${FILE} has been completely FTP'd to ########. Initiating unzip/decrypt/gzip/FTP to mainframe.."
echo "$PROCESS file - ${DIR}${FILE} has been completely FTP'd to ########. Initiating unzip/decrypt/gzip/FTP to mainframe.." | mailx -s "$PROCESS file $FILE has been completely FTP'd to cwyeta01 $DIR. Initiating unzip/decrypt/gzip/FTP to mainframe.." $EMAIL_SUPPORT
break
fi
done

#unzip file

echo "Initiating unip of $FILE"
unzip -o $FILE
RC=$?
if (( $RC != 0 )); then
echo "$PROCESS - Error in unzip command for $FILE....investigate."
echo "$PROCESS - Error in unzip command for $FILE....investigate." | mailx -s "$PROCESS - Error in unzip" $EMAIL_SUPPORT
else
echo "$PROCESS - Unzip of $FILE completed successfully."
fi

#echo "$(date +%T) - Sleeping for 5 minutes"
#sleep 300

UNZIP_FILE=`ls AXEM.BM0${DATA_MONTH}OT.conv.*`
echo "UNZIP_FILE=$UNZIP_FILE"

#decrypt file
sudo -u gpg /usr/bin/gpg --homedir=/home/gpg/.gnupg --no-tty --decrypt <${UNZIP_FILE}> ${DECRYPT_FILE}
set -x
RC=$?
if (( $RC != 0 )); then
echo "error in decrypting $PROCESS - file $UNZIP_FILE on ########. Investigate...."
echo "error in decrypting $PROCESS - file $UNZIP_FILE on ########. Investigate...." | mailx -s "$PROCESS file - error in decryption. Investigate..." $EMAIL_SUPPORT
exit 1

else

echo "$UNZIP_FILE decrypted successfully to file ${DECRYPT_FILE}. Initiating gzip of $DECRYPT_FILE"
gzip $DECRYPT_FILE
#echo "$(date +%T) - Sleeping for 15 minutes"
#sleep 900
RC=$?

if (( $RC != 0 )); then
echo "Error in gzip command within $PROCESS....investigate."
echo "Error in gzip command within $PROCESS....investigate." | mailx -s "$PROCESS - failed within gzip step" $EMAIL_SUPPORT

else
echo "gzip of $DECRYPT_FILE complete. Initiating FTP for ${DECRYPT_FILE}.gz"
fi

# initiate file transfer
ftp -v -n cpu3 <<-!
binary
quote user $USER
quote pass $PASS
quote site RECFM=$RECFM LRECL=$LRECL BLKSIZE=$BLKSIZE UNIT=$UNIT VCOUNT=$VCOUNT RETPD=$RETPD
put ${DECRYPT_FILE}.gz $MFFILE
bye
!
# done with FTP
# ensure FTP transmitted successfully
grep -q "Data bytes written:" $LOG_NAME
RC2=$?

if (( $RC2 == 0 )); then
# capture record count
((NUMRECS=`grep "Data bytes written:" ${LOG_NAME} | awk '{print $4}' | tr -d '.' | tr -d '\r'`/$LRECL))
# integer NUMBYTES=`grep "Data bytes written:" ${LOG_NAME} | awk '{print $4}' | tr -d '.' | tr -d '\r'`
#echo "NUMBYTES=$NUMBYTES"}
#(( NUMRECS=$NUMBYTES/$LRECL ))
#echo "NUMRECS=$NUMRECS"
NUMRECSF=$(echo $NUMRECS | sed -e :a -e 's/^\([^.]*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta')
echo "NUMRECSF=$NUMRECSF"
echo "$Script_Name has completed FTP to mainframe. You can expect $MFFILE with $NUMRECSF records to be on the mainframe."
echo "$Script_Name has completed FTP to mainframe.. You can expect $MFFILE with $NUMRECSF records to be on the mainframe." | mailx -s "$Script_Name has FTP'd BAMH file to mainframe" $EMAIL_SUPPORT

else
echo "$Script_Name has failed within the FTP step to the mainframe."
echo "$Script_Name has failed within the FTP step to the mainframe." | mailx -s "$PROCESS FTP failure" $EMAIL_SUPPORT
fi
fi

#FTP log file to midway
ftp -nv midway <<-!
quote user $PUSER
quote pass $PPASS
cd $ODRIVE
pwd
put ${LOG}/$(basename $0 .ksh)"_$(date +%m%d%Y).log $(basename $0 .ksh)"_$(date +%m%d%Y).log
ls
bye
!

# notify users that BAMH log file is on O Drive
echo "$MESSAGE" | mailx -s "$SUBJECT" $EMAIL_SUPPORT



## end of job cleanup
mv -f $FILE ${FILE}.pulled
echo "$FILE has been renamed to ${FILE}.pulled"
rm -f $UNZIP_FILE
echo "$UNZIP_FILE has been deleted from $DIR"
rm -f ${DECRYPT_FILE}.gz
echo "${DECRYPT_FILE}.gz has been deleted from $DIR"

exit 0
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

i can not figure this out

I am having problems scripting in UNIX. I am currently attending school and for the first time I am being introduced to scripting. My problem is I am supposed to enhance the spell_check by adding a third optional argument. The third argument is to specify a list of words to be added to the... (1 Reply)
Discussion started by: steph
1 Replies

2. UNIX for Dummies Questions & Answers

figure it out

hi there i am new to this site and this linux and unix stuff so kind of plz help me out hoe to start the stuff.... (1 Reply)
Discussion started by: cool_dude
1 Replies

3. Shell Programming and Scripting

Cant figure out this..

Hi, I need a little help here. I am exporting user info from a PSQL database and everything is working with the exception of this: 10029008:dsAuthMethodStandard\:dsAuthClearText:classword:10029008:2004:10029008:10029008:/home/student/1002/90/08:10029008 It is putting a colon right before the... (1 Reply)
Discussion started by: Stud33
1 Replies

4. IP Networking

How do I figure out the subnet?

Hi, How do I get subnet from this: 10.252.0.138/25 Tnx (2 Replies)
Discussion started by: mehrdad68
2 Replies

5. Solaris

Can't figure out how to automount with subdirectories

I want to be able to mount 3 directories. But two are a subdirectories of the first. /opt/gnu sunpefs02:/export/home/sunpefs02-5/replication/8600finland/gnu /opt/gnu/bin sunpefs02:/export/home/sunpefs02-5/replication/8600finland/gnu/bin-sparc-SunOS /opt/gnu/lib... (3 Replies)
Discussion started by: srhadden
3 Replies

6. UNIX for Dummies Questions & Answers

How to figure out what each IP address is used for?

Hi, I have inherited a server at work that has one IP and two virtual IP's. It is live and I want to figure out what each IP is being used for. I thought of NETSTAT but I cannot figure out how to get it to list what each IP is listening for. ANy advice? (8 Replies)
Discussion started by: mojoman
8 Replies

7. UNIX for Advanced & Expert Users

Can't figure out how this is working

I have two machines, each with a virtual interface, with the following configurations: Machine1: eth2 Link encap:Ethernet HWaddr 00:09:6B:19:E5:05 inet addr:172.16.0.201 Bcast:172.16.0.255 Mask:255.255.255.0 eth2:0 Link encap:Ethernet HWaddr 00:09:6B:19:E5:05 ... (0 Replies)
Discussion started by: druidmatrix
0 Replies

8. UNIX for Dummies Questions & Answers

Can't figure this one out --

I'm putting together a shell script while I'm learning UNIX -- just for myself. It's a little script that simply takes some vendor names and writes them to a file. So far I'm at the stage where the user enters the name of the file and places it in a folder called vendorlists: * ) touch... (5 Replies)
Discussion started by: Straitsfan
5 Replies

9. UNIX for Dummies Questions & Answers

Can't figure out why this repeats

#!/bin/sh while IFS=: read address port; do : ${port:=443} address=$address port=$port cd $f_location number=`grep "$address" thing.txt -A 1 | grep "addresses=" | cut -d'"' -f2` echo "$address,$port,$number,$answer" >>... (9 Replies)
Discussion started by: shade917
9 Replies

10. Shell Programming and Scripting

Help with change significant figure to normal figure command

Hi, Below is my input file: Long list of significant figure 1.757E-4 7.51E-3 5.634E-5 . . . Desired output file: 0.0001757 0.00751 0.00005634 . . . (10 Replies)
Discussion started by: perl_beginner
10 Replies
All times are GMT -4. The time now is 01:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy