daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Jan 24th, 2016 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # campaign Aactivation and Notification report genereted path
  4. #DIR=/usr/local/actrule/report/tenant1
  5. DIR=/var/tmp/
  6. OUTPUTDIR=/var/tmp
  7. #report_confDir=/usr/local/actrule/bin/custo_reports
  8. report_confDir=/var/tmp
  9. timestamp=$(date +%Y%m%d%H%M%S)
  10. #script logs
  11. LOG=/usr/local/actrule/logs/EEBulkContact.log
  12. echo -e "\nScript start time: $timestamp"  >> $LOG
  13.  
  14. LOCK_DIR=/nfsdata/files/my_tmp_mcrh_report_lock
  15.  
  16. UPLOAD(){
  17. username=$(cat $report_confDir/report_conf.txt|grep USERNAME|awk -F "=" '{ print $2 }')
  18. password=$(cat $report_confDir/report_conf.txt|grep SUDOPASSWORD|awk -F "=" '{ print $2 }')
  19. ip=$(cat $report_confDir/report_conf.txt|grep IP|awk -F "=" '{ print $2 }')
  20. if [ ! -z $username ] && [ ! -z $password ] && [ ! -z $ip ]
  21. then
  22. echo -e " SFTP login credential has been retrieve from $report_confDir/report_conf.txt " >> $LOG
  23. echo -e "$password\n" | sudo -S sftp -oIdentityFile=/usr/local/actrule/conf/customer/private_key $username@$ip << END_SCRIPT
  24. #sftp -oIdentityFile=/usr/local/actrule/conf/customer/private_key eeftp@192.168.0.38 >> $LOG << END_SCRIPT
  25. cd /reporting/
  26. mput MCRH_CONTACTS_$CURRENTDATE*
  27. quit
  28. END_SCRIPT
  29. if [ $? -eq 0 ]
  30. then
  31. echo -e "Report has been successfully uploaded to SFTP location" >> $LOG
  32. else
  33. echo -e "SFTP Login Error" >> $LOG
  34. /bin/rm -rf $LOCK_DIR
  35. exit 1
  36. fi
  37. else
  38. echo "SFTP login details are not available in $report_confDir/report_conf.txt " >> $LOG
  39. /bin/rm -rf $LOCK_DIR
  40. exit 1
  41. fi
  42. }
  43.  
  44. # function is written to retrive msisdn from campaign_activation report and replace first two digit "44" by "0"
  45. campaign_activation_msisdn(){
  46. rm -rf /var/tmp/removefirsttwodigit.txt
  47. cd $DIR
  48. CURRENT_DATE=`date --date="0 day ago" "+%Y-%m-%d"`
  49. #count variable is used to check the number of campaign_activation report on source dirctory location
  50. #count=`(ls -lrth grep Notification_details*|grep $CURRENT_DATE|awk -F " " '{ print $9 }'|wc -l)`
  51. if [ -f $DIR/Notification_details_$CURRENT_DATE*.gz ]
  52. then
  53. ls -lrth | grep "Notification_details*"|grep $CURRENT_DATE|tail -1|awk -F " " '{ print $9 }'|while read line
  54. do
  55. zcat $line|awk -F ";" '{ print $1","$2","$5","$8 }'|sed 's/^..//'|sed 's/^/0/'
  56. done > /var/tmp/removefirsttwodigit.txt
  57. else
  58. echo "Notification_details report doesnot exist!" >> $LOG
  59. /bin/rm -rf $LOCK_DIR
  60. exit 1
  61. exit
  62. fi
  63. sed -i 1d /var/tmp/removefirsttwodigit.txt
  64. }
  65.  
  66. if mkdir $LOCK_DIR; then
  67. echo "Locking succeeded" >> $LOG
  68. #function call
  69. campaign_activation_msisdn
  70. if [ -s /var/tmp/removefirsttwodigit.txt ]
  71. then
  72. #Static Parameters
  73. NA21=",,,,,,,,,,,,"
  74. NA22=",,,,,,,"
  75. NA23=",,,,"
  76. NA24=",,,,,,,,,,,"
  77. ATLFLAG="0"
  78. CONTACTTESTFLAG="0"
  79. CELLCODE="Target"
  80. CUSTOMERTYPE="PM"
  81. CUSTOMERSTATUS="A"
  82. Brand="EE"
  83.  
  84. #Parameters getting from configurable files
  85.   if [ -s $report_confDir/report_conf.txt ]
  86.   then
  87.   SOURCESYSTEMID=$(cat $report_confDir/report_conf.txt|grep SOURCE_SYSTEM_ID|awk -F "=" '{ print $2 }')
  88.   MKTGACTIVITYCODE=$(cat $report_confDir/report_conf.txt|grep MKTG_ACTIVITY_CODE|awk -F "=" '{ print $2 }')
  89.   #codition to check in case report_conf contain any paramater empty !
  90.     if [ -z "$SOURCESYSTEMID" -a "$SOURCESYSTEMID"=" " ]
  91.     then
  92.     SOURCESYSTEMID="SourceSystemId"
  93.     fi
  94.     if [ -z "$MKTGACTIVITYCODE" -a "$MKTGACTIVITYCODE"=" " ]
  95.     then
  96.     MKTGACTIVITYCODE="MktgActivityCode"
  97.     fi
  98.   else
  99.   echo "report_conf file not exist at location $DIR so defult paramater set" >> $LOG
  100. #default paramater
  101.   SOURCESYSTEMID="SourceSystemId"
  102.   MKTGACTIVITYCODE="MktgActivityCode"
  103.   fi
  104.   MKTGMSGCODEEMAIL=$(cat $report_confDir/report_conf.txt|grep MKTG_MSG_CODE_EMAIL|awk -F "=" '{ print $2 }')
  105.   MKTGMSGCODESMS=$(cat $report_confDir/report_conf.txt|grep MKTG_MSG_CODE_SMS|awk -F "=" '{ print $2 }')
  106.   dos2unix /var/tmp/removefirsttwodigit.txt
  107.   cat /var/tmp/removefirsttwodigit.txt|while read line
  108.   do
  109.   CURRENT_DATE_TIME=`date --date="0 day ago" "+%Y%m%d%H%M%S%s%5N"`
  110.   msidn=$(echo $line | cut -d',' -f1)
  111.   channel=$(echo $line | cut -d',' -f4)
  112.   date=$(echo $line | cut -d',' -f3|sed 's/\-/\//g')
  113.   if [ "$date" != "null" ] && [ "$date" != "NULL" ]
  114.   then
  115.   date1=$(echo $date|awk -F " " '{ print $1 }')
  116.   date2=$(echo $date|awk -F " " '{ print $2 }')
  117.   date3=$(echo $date1|awk -F "/" '{ print $3"/"$2"/"$1}')
  118.   fortmateddate="$date3 $date2"
  119.   else
  120.   fortmateddate=$date
  121.   fi
  122.   if [ "$channel" == "MAIL" ]
  123.   then
  124.   MKTGMSGCODE=$MKTGMSGCODEEMAIL
  125.   elif [ "$channel" == "SMS" ]
  126.   then
  127.   MKTGMSGCODE=$MKTGMSGCODESMS
  128.   else
  129.   MKTGMSGCODE="MktgMsgCode"
  130.   fi
  131.   echo $msidn$NA21$ATLFLAG$NA22$CUSTOMERTYPE","$CUSTOMERSTATUS",,"$fortmateddate$NA23$MKTGACTIVITYCODE","$MKTGMSGCODE","$channel",,"$CELLCODE",,,"$msidn$CURRENT_DATE_TIME$","$CONTACTTESTFLAG","$SOURCESYSTEMID$NA24$Brand",,"
  132.   done > $OUTPUTDIR/OUTPUT21.csv
  133.   CURRENTDATE=`date --date="0 day ago" "+%Y%m%d"`
  134.  
  135.   REPORTNAME21="MCRH_CONTACTS_"$CURRENTDATE"_"$USER"_Activity"
  136. #spliting file as per static define count
  137.   cd $OUTPUTDIR
  138.   count=$(wc -l $OUTPUTDIR/OUTPUT21.csv|awk -F " " '{ print $1 }')
  139.   echo $count
  140.   if [ $count > 1000000000 ]
  141.   then
  142.   cat $OUTPUTDIR/OUTPUT21.csv|split -l 1000000000
  143. #number=$(ls -lrth xa*| wc -l)
  144.   ls -lrth xa*|awk -F " " '{ print $9 }' > tempfilename
  145.   count1=0
  146.   cat tempfilename |while read line
  147.   do
  148.   count1=$((count1 + 1))
  149.   if [ $count1 -le 9 ]
  150.   then
  151.   mv $line $REPORTNAME21"_00"$count1".dat"
  152.   sed -i '1iMSISDN,EMAIL_ADDRESS,COMPANY_NAME,LAST_NAME,FIRST_NAME,TITLE,DATE_OF_BIRTH,ADDRESS_1,ADDRESS_2,ADDRESS_3,ADDRESS_4,POSTCODE,ATL_FLAG,ACCOUNT_ID,ACCOUNT_SK,SUBSCRIBER_ID,SUBSCRIBER_SK,NODE_ID,CUSTOMER_SK,CUSTOMER_TYPE,CUSTOMER_STATUS,LIST_DATE,PLANNED_START_DATE,PLANNED_END_DATE,ACTUAL_CONTACT_DATE,EXPIRATION_DATE,MKTG_ACTIVITY_CODE,MKTG_MSG_CODE,CONTACT_CHANNEL_CODE,CREATIVE_CODE,CELL_CODE,VENDOR_CODE,TREATMENT_TAG_CODE,UNIQUE_TRACKING_ID,CONTACT_TEST_FLAG,SOURCE_SYSTEM_ID,CONTACT_PARAMETER_001,CONTACT_PARAMETER_002,CONTACT_PARAMETER_003,CONTACT_PARAMETER_004,CONTACT_PARAMETER_005,CONTACT_PARAMETER_006,CONTACT_PARAMETER_007,CONTACT_PARAMETER_008,CONTACT_PARAMETER_009,CONTACT_PARAMETER_010,BRAND,URN' $REPORTNAME21"_00"$count1".dat"
  153.   elif [ $count1 -le 99 ]
  154.   then
  155.   mv $line $REPORTNAME21"_0"$count1".dat"
  156.   sed -i '1iMSISDN,EMAIL_ADDRESS,COMPANY_NAME,LAST_NAME,FIRST_NAME,TITLE,DATE_OF_BIRTH,ADDRESS_1,ADDRESS_2,ADDRESS_3,ADDRESS_4,POSTCODE,ATL_FLAG,ACCOUNT_ID,ACCOUNT_SK,SUBSCRIBER_ID,SUBSCRIBER_SK,NODE_ID,CUSTOMER_SK,CUSTOMER_TYPE,CUSTOMER_STATUS,LIST_DATE,PLANNED_START_DATE,PLANNED_END_DATE,ACTUAL_CONTACT_DATE,EXPIRATION_DATE,MKTG_ACTIVITY_CODE,MKTG_MSG_CODE,CONTACT_CHANNEL_CODE,CREATIVE_CODE,CELL_CODE,VENDOR_CODE,TREATMENT_TAG_CODE,UNIQUE_TRACKING_ID,CONTACT_TEST_FLAG,SOURCE_SYSTEM_ID,CONTACT_PARAMETER_001,CONTACT_PARAMETER_002,CONTACT_PARAMETER_003,CONTACT_PARAMETER_004,CONTACT_PARAMETER_005,CONTACT_PARAMETER_006,CONTACT_PARAMETER_007,CONTACT_PARAMETER_008,CONTACT_PARAMETER_009,CONTACT_PARAMETER_010,BRAND,URN' $REPORTNAME21"_0"$count1".dat"
  157.   else
  158.   mv $line $REPORTNAME21"_"$count1".dat"
  159.   sed -i '1iMSISDN,EMAIL_ADDRESS,COMPANY_NAME,LAST_NAME,FIRST_NAME,TITLE,DATE_OF_BIRTH,ADDRESS_1,ADDRESS_2,ADDRESS_3,ADDRESS_4,POSTCODE,ATL_FLAG,ACCOUNT_ID,ACCOUNT_SK,SUBSCRIBER_ID,SUBSCRIBER_SK,NODE_ID,CUSTOMER_SK,CUSTOMER_TYPE,CUSTOMER_STATUS,LIST_DATE,PLANNED_START_DATE,PLANNED_END_DATE,ACTUAL_CONTACT_DATE,EXPIRATION_DATE,MKTG_ACTIVITY_CODE,MKTG_MSG_CODE,CONTACT_CHANNEL_CODE,CREATIVE_CODE,CELL_CODE,VENDOR_CODE,TREATMENT_TAG_CODE,UNIQUE_TRACKING_ID,CONTACT_TEST_FLAG,SOURCE_SYSTEM_ID,CONTACT_PARAMETER_001,CONTACT_PARAMETER_002,CONTACT_PARAMETER_003,CONTACT_PARAMETER_004,CONTACT_PARAMETER_005,CONTACT_PARAMETER_006,CONTACT_PARAMETER_007,CONTACT_PARAMETER_008,CONTACT_PARAMETER_009,CONTACT_PARAMETER_010,BRAND,URN' $REPORTNAME21"_"$count1".dat"
  160.   fi
  161.   done
  162.   else
  163.   mv /var/tmp/OUTPUT21.csv $REPORTNAME21"_001.dat"
  164.   sed -i '1iMSISDN,EMAIL_ADDRESS,COMPANY_NAME,LAST_NAME,FIRST_NAME,TITLE,DATE_OF_BIRTH,ADDRESS_1,ADDRESS_2,ADDRESS_3,ADDRESS_4,POSTCODE,ATL_FLAG,ACCOUNT_ID,ACCOUNT_SK,SUBSCRIBER_ID,SUBSCRIBER_SK,NODE_ID,CUSTOMER_SK,CUSTOMER_TYPE,CUSTOMER_STATUS,LIST_DATE,PLANNED_START_DATE,PLANNED_END_DATE,ACTUAL_CONTACT_DATE,EXPIRATION_DATE,MKTG_ACTIVITY_CODE,MKTG_MSG_CODE,CONTACT_CHANNEL_CODE,CREATIVE_CODE,CELL_CODE,VENDOR_CODE,TREATMENT_TAG_CODE,UNIQUE_TRACKING_ID,CONTACT_TEST_FLAG,SOURCE_SYSTEM_ID,CONTACT_PARAMETER_001,CONTACT_PARAMETER_002,CONTACT_PARAMETER_003,CONTACT_PARAMETER_004,CONTACT_PARAMETER_005,CONTACT_PARAMETER_006,CONTACT_PARAMETER_007,CONTACT_PARAMETER_008,CONTACT_PARAMETER_009,CONTACT_PARAMETER_010,BRAND,URN' $REPORTNAME21"_001.dat"
  165.   fi
  166.   rm -rf $OUTPUTDIR/tempfilename
  167. else
  168. echo "/var/tmp/removefirsttwodigit.txt file doesnot generated becauese Notification_details not found !" >> $LOG
  169. bin/rm -rf $LOCK_DIR
  170. exit 1
  171. fi
  172. echo -e "\n Files name : MCRH_CONTACTS_$CURRENTDATE has generated at location $OUTPUTDIR " >> $LOG
  173. #calling UPLOAD function to upload the file
  174. echo "\n SFTP file upload function call" >> $LOG
  175. # calling UPLOAD function to upload the file
  176. UPLOAD
  177. /bin/rm -rf $LOCK_DIR
  178. exit 0
  179. else
  180. echo "Lock failed, job already on going"
  181. exit 132
  182. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top