technical skills grow

Responsive Ads Here

Friday, December 11, 2020

CSV FILE IMPORT AND EXPORT IN MYSQL TABLE USING SHEEL SCRIPT

I want to import csv file from database using shell script or send mail to receivers   

#!/bin/bash
user='#####'
pwd='$$$$$$'
user1='@@@@'
pwd1='$$$$$$'

host_name3='192.168.***.***'
host_name4='192.168.***.**'
csv_file_path="/home/qc_data/csv_mh"
#csv_file_path=[ -d /home/qc_data/csv_file ] || mkdir -p /home/qc_data/csv_file

start_date=$(date -d "-4 month" +%Y-%m-%d)

today_date=$(date +"%Y-%m-%d")

#########CREATE_CSV_FILE_FROM_MH#########

mysql -h $host_name3 -u $user -p$pwd -P 3306  -e "select  Station_ID, datadate, MaxTemp, MinTemp, 8_30Humidity, 17_30Humidity, AvgRain, WSMax
from DAILY_SUMMARY_DATA where  datadate between  '$start_date'  and '$today_date'  into OUTFILE '$csv_file_path/76_daily_summary_$today_date.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '' LINES TERMINATED BY '\n';"


#############UPLOAD_FILE_STATEMENT_IS_DONE############

mysql -h $host_name4 -u $user1 -p$pwd1 -P3305 -e " LOAD DATA LOCAL INFILE '$csv_file_path/76_daily_summary_$today_date.csv'  INTO TABLE daily_summary_data_2020  FIELDS TERMINATED BY ','  LINES TERMINATED BY '\n';"


##############INSERT_DATA###############

mysql -h $host_name4 -u $user1 -p$pwd1 -P3305 -e "INSERT INTO  ARMS_PAYOUT_STATION_DATA
(STATION_ID ,DATA_DATE ,MIN_TEMP ,MAX_TEMP  ,RAIN ,MIN_RH  ,MAX_RH  ,MAX_WIND)
select STATION_ID ,DATADATE ,MINTEMP,MAXTEMP ,AvgRAIN ,17_30Humidity,8_30Humidity,WSMax from daily_summary_data_2020  
where STATION_ID>0 ON DUPLICATE KEY UPDATE  MIN_TEMP=daily_summary_data_2020.MINTEMP, MAX_TEMP=daily_summary_data_2020.MAXTEMP,
 RAIN =daily_summary_data_2020.AvgRAIN, MIN_RH=daily_summary_data_2020.17_30Humidity, MAX_RH= daily_summary_data_2020.8_30Humidity,
 MAX_WIND=daily_summary_data_2020.WSMax ;"



rm -rf $csv_file_path/76_daily_summary_$today_date.csv



               

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