Last active
August 1, 2020 11:19
-
-
Save afifhusnul/b732d90c56c354082ab9e35995785076 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## Put your file into /home/$USER/INPUT_RAW | |
## Cut file into 1 piece to Decrypt | |
## Original file /opt/link/cams/data_export/de_simple_sp_20485_20200724T165102.csv | |
## To send into /opt/link/mediation/decrypt/input | |
## execute it as --> ./cmpJobDecrypt.sh <filename.csv> emailId in Digi server ( WITHOUT DOMAIN .digi.com.my) | |
## Sample execution --> ./cmpJobDecrypt.sh <de_simple_sp_20485_20200724T165102.csv> nusnafif | |
log_dttm=`date +"%Y%m%d_%H%M%S"` | |
##--------------- Define for FTP from CMP job & download them | |
dirRemote=/opt/link/cams/data_export | |
dirRaw=/home/$USER/RAW | |
dirInput=/home/$USER/INPUT_RAW | |
dirOutput=/home/$USER/OUTPUT_RAW | |
HOST=xxx.xxx.xxx.xxx | |
USER=userid | |
sftp $HOST <<EOF | |
cd $dirRemote | |
mget $1 $dirInput | |
bye | |
EOF | |
##-------------- Download file DONE | |
##--------------- Define the stuff | |
rcpt='[email protected]' | |
[email protected] | |
inputFile=$dirInput/inputDecrypt.csv | |
outputFile=$dirOutput/output_$log_dttm.csv | |
balanceFile=$dirRaw/balance_result.csv | |
resultFile=$dirRaw/final_result_$log_dttm.csv | |
resultFileZip=$dirRaw/final_result_$log_dttm.zip | |
procFolder=/opt/link/mediation/decrypt/input/ | |
resFolder=/opt/link/mediation/decrypt/output | |
##---------------- Move file name to default name | |
if [ -e $dirInput/$1 ]; then | |
mv $dirInput/de*.csv $dirInput/inputDecrypt.csv | |
##---------------- Cut file into single column | |
cat $inputFile | awk -F";" '{print$1}' > $outputFile | |
cat $inputFile | awk -F";" -v OFS=';' '{ $1=""; print}' > $balanceFile | |
chmod 667 $outputFile | |
##---------------- Move file into mediation decrypt input folder & sleep 5m to wait processing file | |
mv $outputFile $procFolder | |
sleep 5m | |
##---------------- check outputFile in resFolder | |
if [ -e $resFolder/output_$log_dttm.csv ]; then | |
##---------------- Move back to my terithory to further process | |
cat $resFolder/output_$log_dttm.csv > $dirRaw/output_$log_dttm.csv | |
paste -d ";" $dirRaw/output_$log_dttm.csv $balanceFile > $resultFile | |
else | |
##---------------- Processing still on going sleep again for another 10min & process it | |
sleep 10m | |
cat $resFolder/output_$log_dttm.csv > $dirRaw/output_$log_dttm.csv | |
paste -d ";" $dirRaw/output_$log_dttm.csv $balanceFile > $resultFile | |
fi | |
SIZE=$(du -sb $resultFile | awk '{ print $1 }') | |
##---------------- Check size & send result file | |
if ((SIZE<2097152)) ; then | |
echo "File result in attachment" | /bin/mail -s "CMP Decrypt file result" -a $resultFile -r "Alert Dcc<[email protected]>" $2 | |
else | |
/usr/bin/zip $resultFileZip $resultFile && | |
echo "File result in attachment" | /bin/mail -s "CMP Decrypt file result" -a $resultFileZip -r "Alert Dcc<[email protected]>" $2 | |
rm $resultFileZip | |
fi | |
#---------------- Clean up | |
rm $inputFile | |
rm $balanceFile | |
rm $resultFile | |
rm $dirRaw/output_$log_dttm.csv | |
#---------------- End | |
else | |
echo "Job File not found" | |
echo "Job file not found, please check your job file accordingly" | /bin/mail -s "CMP Job file not found" -r "Alert Dcc<[email protected]>" $2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment