Skip to content

Instantly share code, notes, and snippets.

@afifhusnul
Last active August 1, 2020 11:19
Show Gist options
  • Save afifhusnul/f3ceccc8a71b8f2f091852a230c7eca1 to your computer and use it in GitHub Desktop.
Save afifhusnul/f3ceccc8a71b8f2f091852a230c7eca1 to your computer and use it in GitHub Desktop.
#!/bin/sh
## Put your file into /home/$USER/INPUT_RAW
## Cut file into 1 piece to Decrypt
## To send into /opt/link/mediation/decrypt/input
## to execute --> ./cmpExtDecrypt.sh
log_dttm=`date +"%Y%m%d_%H%M%S"`
##--------------- Define the stuff (Change the email ID if necessary)
rcpt='user@domain.com'
digiMail=@domain.com
dirRaw='/home/'$USER'/RAW'
dirInput='/home/'$USER'/INPUT_RAW'
dirOutput='/home/'$USER'/OUTPUT_RAW'
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
pipeInputFile=$dirRaw/pipeInput.txt
pipeBalanceFile=$dirRaw/pipeBalance.txt
procFolder=/opt/link/mediation/decrypt/input/
resFolder=/opt/link/mediation/decrypt/output
#---------------- Move file name to default name
if [ "$(ls -A $dirInput)" ]; then
mv -f $dirInput/* $dirInput/inputDecrypt.csv
#---------------- Cut file into single column
cat $inputFile | awk -F";" '{print$1}' > $outputFile
cat $inputFile | awk -F";" -v OFS=';' '{ $1=""; print}' > $balanceFile
#echo `wc -l $inputFile` " --> Total Field =" `head -n 1 $inputFile > $pipeInputFile && awk -F ';' '{print NF}' $pipeInputFile`
#echo `wc -l $balanceFile` " --> Total Field =" `head -n 1 $balanceFile > $pipeBalanceFile && awk -F ';' '{print NF}' $pipeBalanceFile`
#ls -l $dirOutput && head -n 10 $outputFile
chmod 667 $outputFile
#---------------- Move file into mediation decrypt input folder
mv $outputFile $procFolder
sleep 10m
##---------------- 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 5m
cat $resFolder/output_$log_dttm.csv > $dirRaw/output_$log_dttm.csv
paste -d ";" $dirRaw/output_$log_dttm.csv $balanceFile > $resultFile
fi
##---------------- check outputFile in resFolder
#cat $resFolder/output_$log_dttm.csv > $dirRaw/output_$log_dttm.csv
#paste -d ";" $dirRaw/output_$log_dttm.csv $balanceFile > $resultFile
SIZE=$(du -sb $resultFile | awk '{ print $1 }')
#---------------- Send result file
if ((SIZE<2097152)) ; then
echo "File result in attachment" | /bin/mail -s "CMP Decrypt file result" -a $resultFile -r "Alert Dcc<alert-dcc@digi.com.my>" $1
else
/usr/bin/zip $resultFileZip $resultFile &&
echo "File result in attachment" | /bin/mail -s "CMP Decrypt file result" -a $resultFileZip -r "Alert Dcc<alert-dcc@digi.com.my>" $1
rm $resultFileZip
fi
#---------------- Clean up
rm $inputFile
#rm $pipeInputFile
#rm $pipeBalanceFile
rm $balanceFile
rm $resultFile
rm $dirRaw/output_$log_dttm.csv
#---------------- End
else
echo "Folder is empty"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment