#!/bin/bash -e #HOME="/home/compegence/customer" #Directories homeDir=$HOME/customer/MMT configDir=$homeDir/conf input_file=$configDir/etl-config.txt declare -A credentials while IFS="=" read -r key value; do credentials[$key]=$value done < <( sed -e '/^\s*$/ d' -e '/^#/ d' $input_file ) user=${credentials[user]} password=${credentials[password]} host=${credentials[host]} db=${credentials[db]} protocol=${credentials[protocol]} server=${credentials[server]} psql_base_arg="postgresql://$user:$password@$host/$db" #dbname="mmt_tdm" #port=5432 Get_Email_Ids () { #client_id=$1 echo $client_id email_ids=`psql $psql_base_arg -t -c "select runschedule_status_email from fw_core.fw_m_client where client_id=$client_id"` #echo $email_ids #mail -a "Content-type: text/html" -s "Mail configuration Completed" $email_ids -a "From: noreply@forewarn.com" < Output.html } #echo $psql_base_arg Get_FileUpload_Status (){ #echo -e "MIME-Version: 1.0\nContent-Type: multipart/plain" >Output.txt echo -e "--asdfghjkl\nContent-Type: text/plain; charset=utf-8\n\nAlerts for the job run status\n\n--asdfghjkl\nContent-Type: text/html; charset=utf-8\n\n\n\n\n\t\n\t\t\n\t\n

Mahindra TDMS - Latest Flles Update Status

" > Output.txt #echo "

Mahindra TDMS - Latest Files Update Status

" >> Output.txt #echo " " >>Output.txt psql $psql_base_arg -H -c "select run_schedule_id, file_syspk, file_mnemonic, file_name, end_status as status, end_time load_time from fw_core.fw_jobctl_file_runschedule where run_schedule_id in (select max(run_schedule_id) from fw_core.fw_jobctl_file_runschedule) order by run_schedule_id, file_syspk, end_status desc;" >> Output.txt echo -e "\n\t\n\t\t\n\t\n

Error Files

" >> Output.txt psql $psql_base_arg -H -c "select A.run_schedule_id, A.file_syspk, A.file_mnemonic, A.file_name, B.sheet_id, B.sheet_name, A.end_status, A.end_time load_time from fw_core.fw_jobctl_file_runschedule a, fw_core.fw_jobctl_file_sheet_runschedule b where a.run_schedule_id = (select max(run_schedule_id) from fw_core.fw_jobctl_file_runschedule) and a.file_syspk = b.file_syspk and (b.file_sheet_mnemonic != '' or b.file_sheet_mnemonic is not null) and b.end_status='error' order by A.run_schedule_id, b.file_syspk, b.sheet_id desc" >> Output.txt echo -e "\n\n--asdfghjkl" >> Output.txt } Send_Mail () { Get_Email_Ids echo $email_ids mail -a "Content-Type: multipart/alternative; boundary=asdfghjkl" -s "FIle Load Status" $email_ids -a "From: noreply@forewarn.com" < Output.txt } #mail -a "Content-type: text/html" -s "Mail configuration Completed" muin.shariff@compegence.com nagaraj.kulkarni@compegence.com dheepa.k@compegence.com abdur.rahman@compegence.com jagadish.puvvada@compegence.com -a "From: noreply@forewarn.com" < Output.html if [ -z "$1" ] then client_id=20 Get_FileUpload_Status Send_Mail; else Get_FileUpload_Status Send_Mail; fi psql $psql_base_arg -q -c "update fw_core.fw_jobctl_runschedule_jobstep set end_status_note ='email_completed', end_status='success',end_time = now() where job_script_type = 'shell_script' and latest_runschedule_flag='1' and job_name= 'sending mail'"