Last active
August 1, 2020 11:19
-
-
Save afifhusnul/f3ceccc8a71b8f2f091852a230c7eca1 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 | |
## 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='[email protected]' | |
[email protected] | |
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<[email protected]>" $1 | |
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]>" $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