technical skills grow

Responsive Ads Here

Saturday, August 15, 2020

SHELL SCRIPT

                                  WELCOME TO SHELL SCRIPT WORLD

!/bin/bash

user='backup_user'
pwd1='backup@321'
host_name1='192.168.103.54'
host_name2='192.168.103.71'
host_name3='192.168.103.76'
[ -d /home/daily_csv_file ] || mkdir -p /home/daily_csv_file
csv_file_path="/home/daily_csv_file"
full_date=$(date +"%d-%b-%Y:%H:%M:%S")

start_date=$(date --date="5 day ago" +"%Y-%m-%d")
end_date=$(date  +"%Y-%m-%d")
point_time="00:00:00"
#start_date="2020-01-25"
#end_date="2020-01-26"
#point_start_time="00:00:00"
point_end_time="23:55:50"
first_start_date="$start_date $point_time"
#first_end_date="$end_date $point_time"
#first_start_date="$start_date $point_start_time"
first_end_date="$end_date $point_end_time"

mysql -h $host_name1 -u $user -p$pwd1  -e   "call db.MH_non_qc_five_data('$first_start_date','$first_end_date');"
mysql -h $host_name2 -u $user -p$pwd1  -e   "call db.MH_non_qc_five_data('$first_start_date','$first_end_date');"
mysql -h $host_name3 -u $user -p$pwd1  -e   "call db.MH_non_qc_five_data('$first_start_date','$first_end_date');"
 

query54="#select IMEI_ID, STATE, DISTRICT, TEHSIL, REVENUE_CIRCLE, STATION_NAME, DATADATE, IS_UPDATED union
select *
 from test.non_qc_data;"


query71="select *
#IMEI_ID, STATE, DISTRICT, TEHSIL, REVENUE_CIRCLE, STATION_NAME, DATADATE, IS_UPDATED
 from test.non_qc_data;"

query76="select *
 #IMEI_ID, STATE, DISTRICT, TEHSIL, REVENUE_CIRCLE, STATION_NAME, DATADATE, IS_UPDATED
 from test.non_qc_data;"

  echo "ExecutingOn54"
 

  mysql -u $user -p$pwd1 -h 192.168.103.54 -P 3306 aws_mh -e "$query54" | sed 's/\t/,/g' > $csv_file_path/Mh_non_qc_data_$start_date.csv
 

  echo "ExecutingOn71"
 

 mysql -u $user -p$pwd1 -h 192.168.103.71 -P 3306 aws_mh -e "$query71" | sed 's/\t/,/g' | awk '{if(NR>1)print}'  >> $csv_file_path/Mh_non_qc_data_$start_date.csv
 

echo "ExecutingOn76"
 mysql -u $user -p$pwd1  -h 192.168.103.76 -P 3306 aws_mh -e "$query76" | sed 's/\t/,/g' | awk '{if(NR>1)print}' >> $csv_file_path/Mh_non_qc_data_$start_date.csv


echo "PFA of MH_five_day_non_qc_data_data" | mailx -s "MH_five_day_non_qc_data_File" -a  $csv_file_path/Mh_non_qc_data_$start_date.csv  tarun.*****@********.com
 

if [ "$?" -eq 0 ]
then
        echo -e  "csv file is created successfully"
        echo "Process completed successfully"
else
         echo -e "csv file is not created"
         echo "Process failed"
         exit 1
fi

#*/1   *  * * *   cd /home/back_script/test/ &&  /usr/bin/python   /home/back_script/test/csvsend.py >> a.log

Part 2: Export & Import CSV file from mysql by shell script

No comments:

Post a Comment

Powered by Blogger.

Labels

Contact Form

Name

Email *

Message *

Search This Blog

Blog Archive

Ad Code

Responsive Advertisement

Recent Posts