ZBLOG

if [ $? -ne 0 ]; then mv ${Csvfile}/${file} ${Csvfile}/${time2}errofile/ echo ${tablename} "is failed load" errorinfo_path="/data/loadmysql/log/${tablename}.txt" #load错误数据信息到监控表 mysql -h 192.168.120.18

Explanation:

This is a bash script that checks if the previous command executed successfully. If it did not, it moves the file to an error directory and logs an error message along with the table name that failed to load. It also inserts this information into a monitoring table in a MySQL database.

If the previous command executed successfully, it moves the file to a backup directory and continues to the next iteration of the loop.

The variables used in the script are:

  • $? - the exit status of the previous command
  • ${Csvfile} - the directory where the CSV files are stored
  • ${file} - the name of the CSV file being loaded
  • ${time2} - the current date and time in the format YYYY-mm-dd_HH-MM-SS
  • ${tablename} - the name of the table being loaded
  • ${start_time} - the start time of the script execution
  • ${errorinfo_path} - the path to the log file containing error information
  • mysql - the command-line client for MySQL
  • -h - the host name or IP address of the MySQL server
  • -P - the port number of the MySQL server
  • -u - the username to use when connecting to the MySQL server
  • -p - the password to use when connecting to the MySQL server
  • test - the name of the MySQL database to use
  • load_error_info - the name of the monitoring table in the database

Overall, this script helps to automate the process of loading data from CSV files into a MySQL database while also providing error handling and monitoring capabilities.

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=545

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?