#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <strstream>
#include <fstream> //ifstream fin("ent_list");
#include "/usr/local/mysql/include/mysql/mysql.h"
//const char mysqlServer[20] = "172.16.1.77";
const char mysqlServer[20] = "10.88.15.114";
const char user[20]="web";
const char password[20]="sinatest";
const char database[20]="enterprise";
const char database2[20]="enterprisemail";
unsigned int port=3306;
int flag=0;
char name[1024];
char query[1024];
char query2[1024];
char file_path[1024]="./ent_list"; //过期企业ID 数据文件
char file_path1[1024]="/tmp/enterprise.domain.successful.log"; //enterprise.domain的数据库select语句成功日志
char file_path2[1024]="/tmp/enterprise.domain.failed.log"; //enterprise.domain的数据库select语句失败日志
char file_path3[1024]="/tmp/enterprisemail.domain.successful.log"; //enterprisemail.domain数据库的update修改成功日志
char file_path4[1024]="/tmp/enterprisemail.domain.failed.log"; //enterprisemail.domain数据库的update语句修改失败日志
char file_path5[1024]="/tmp/enterprisemail.domain.successful.recover.log"; //enterprisemail.domain数据库的update语句修改失败日志
using namespace std;
//去掉读出的一行的前后空格
void trim(string& str)
{
str.erase(str.find_last_not_of(' ')+1, string::npos);
str.erase(0, str.find_first_not_of(' '));
}
//去前后空格函数结束
int main(int argv,char * argc[])//main函数体
{
time_t t;
struct tm *x;
time( &t );
x = localtime(&t);
MYSQL myData,myData2,*sock,*sock2;
MYSQL_RES *res;
MYSQL_FIELD *fd;
MYSQL_ROW row;
mysql_init( &myData );
mysql_init( &myData2 );
if(argv!=2)
{
cout << "_____________________请在ent_list文件放入企业ID_______________\n";
cout << "|然后请传入参数? (1,0) |\n";
cout << "|传入1:ent_dated_restet 1 为打开过期续费企业 |\n";
cout << "|传入0:ent_dated_restet 0 关闭过期没有续费企业 \n";
cout << "|______________________________________________________________|\n";
cout << "|_你只要将要关闭或者打开的企业ID放到ent_list由1或者0来控制即可_|\n";
cout << "| Warn: 连续一行一个企业ID(domain.enterpriseid) \n";
cout << "|______________________________________________________________|\n";
return 0;
}
flag=atoi(argc[1]); //判断是关闭企业还是恢复企业
if(!(sock = mysql_real_connect( &myData, mysqlServer, user, password, database,port,NULL,0)))
{
printf("can not connect mysql error...(enterprise.domain)\n");
return 0;
}
if(!(sock2 = mysql_real_connect( &myData2, mysqlServer, user, password, database2,port,NULL,0)))
{
printf("can not connect mysql error...(enterprisemail.domain)\n");
return 0;
}
//读取文本
ifstream fin(file_path);
ofstream fout1(file_path1,ios_base::app);//enterprise.domain的数据库select语句成功日志
ofstream fout2(file_path2,ios_base::app);//enterprise.domain的数据库select语句失败日志
ofstream fout3(file_path3,ios_base::app);//enterprisemail.domain数据库的update修改成功日志
ofstream fout4(file_path4,ios_base::app); //enterprisemail.domain数据库的update语句修改失败日志
ofstream fout5(file_path5,ios_base::app); //enterprisemail.domain数据库的update语句修改失败日志
string str;
while(getline(fin,str))
{
trim(str);//去掉读出的一行前后空格
char buffer[1024];
int str_to_int=atoi(str.c_str());
sprintf(buffer,"%d",str_to_int);
if(strcmp(str.c_str(),buffer)!=0)
{
cout <<str<<"Have contain special character in one line,please check...\n";
fout2 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<< "Enterpriseid:\t" <<str <<"\tHave contain special character in one line,please check...\n";
continue;
}
memset(buffer,0,1024);//销毁临时变量
//判断是否是数字
if (!str.length())
{
printf("请检查一下你的./ent_list里面是否有空行...\n");
return 0;
}
strcpy(query,"select name from `domain` where name not like \"%shenbak\" and enterpriseid=");
strcat(query,str.c_str());
cout<<query<<"\n";
if( mysql_query(&myData, query) != 0 )
{
fout2 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<< "Enterpriseid:\t" <<str <<"\t Failed!\n"; //失败的select 查询记录到日志enterprise.domain.failed.log
continue;
}else{
res = mysql_store_result( &myData);
while(row = mysql_fetch_row(res))
{
fout1 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<<"Enterpriseid:\t" << str <<"\tname:\t" << row[0] <<"\t Select sql Run Successful!\n";//写日志
strcpy(name,row[0]);
if(flag==0)
{
strcpy(query2,"update\t`domain` set name=replace(name,name,concat(name,\"shenbak\")) where name not like \"%shenbak\" and name=");
strcat(query2,"'");
strcat(query2,name);
strcat(query2,"'");
cout << query2<<"\n";
}
if(flag==1)
{
strcpy(query2,"update `domain` set name=replace(name,\"shenbak\",\"\") where name like \"%shenbak\" and name=");
strcat(query2,"'");
strcat(query2,name);
strcat(query2,"shenbak");
strcat(query2,"'");
}
if( mysql_query(&myData2, query2) != 0 )
{
fout4 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<< "Enterpriseid:\t" << str <<"\tname:\t"<<name<<"\tupdate query failed!\n";
continue;
}else{
if(flag==0)
{
fout3 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<<"Enterpriseid:\t" << str << "\tname:\t" <<name<<"\tupdate query successful!\n";
//写屏蔽日志
}
if(flag==1)
{
fout5 <<x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<<"Enterpriseid:\t" << str << "\tname:\t" <<name<<"\tupdate query successful!\n";
//写日恢复日志
}
}
memset(name,0,1024);
}
str="";
memset(query,0,1024);
memset(query2,0,1024);
}
}
mysql_free_result(res);
mysql_close(&myData);
mysql_close(&myData2);
fin.close();
fout1.close();
fout2.close();
fout3.close();
fout4.close();
fout4.close();
cout << "\nAll task run ok....Goodbye!\n";
}
#include <time.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <strstream>
#include <fstream> //ifstream fin("ent_list");
#include "/usr/local/mysql/include/mysql/mysql.h"
//const char mysqlServer[20] = "172.16.1.77";
const char mysqlServer[20] = "10.88.15.114";
const char user[20]="web";
const char password[20]="sinatest";
const char database[20]="enterprise";
const char database2[20]="enterprisemail";
unsigned int port=3306;
int flag=0;
char name[1024];
char query[1024];
char query2[1024];
char file_path[1024]="./ent_list"; //过期企业ID 数据文件
char file_path1[1024]="/tmp/enterprise.domain.successful.log"; //enterprise.domain的数据库select语句成功日志
char file_path2[1024]="/tmp/enterprise.domain.failed.log"; //enterprise.domain的数据库select语句失败日志
char file_path3[1024]="/tmp/enterprisemail.domain.successful.log"; //enterprisemail.domain数据库的update修改成功日志
char file_path4[1024]="/tmp/enterprisemail.domain.failed.log"; //enterprisemail.domain数据库的update语句修改失败日志
char file_path5[1024]="/tmp/enterprisemail.domain.successful.recover.log"; //enterprisemail.domain数据库的update语句修改失败日志
using namespace std;
//去掉读出的一行的前后空格
void trim(string& str)
{
str.erase(str.find_last_not_of(' ')+1, string::npos);
str.erase(0, str.find_first_not_of(' '));
}
//去前后空格函数结束
int main(int argv,char * argc[])//main函数体
{
time_t t;
struct tm *x;
time( &t );
x = localtime(&t);
MYSQL myData,myData2,*sock,*sock2;
MYSQL_RES *res;
MYSQL_FIELD *fd;
MYSQL_ROW row;
mysql_init( &myData );
mysql_init( &myData2 );
if(argv!=2)
{
cout << "_____________________请在ent_list文件放入企业ID_______________\n";
cout << "|然后请传入参数? (1,0) |\n";
cout << "|传入1:ent_dated_restet 1 为打开过期续费企业 |\n";
cout << "|传入0:ent_dated_restet 0 关闭过期没有续费企业 \n";
cout << "|______________________________________________________________|\n";
cout << "|_你只要将要关闭或者打开的企业ID放到ent_list由1或者0来控制即可_|\n";
cout << "| Warn: 连续一行一个企业ID(domain.enterpriseid) \n";
cout << "|______________________________________________________________|\n";
return 0;
}
flag=atoi(argc[1]); //判断是关闭企业还是恢复企业
if(!(sock = mysql_real_connect( &myData, mysqlServer, user, password, database,port,NULL,0)))
{
printf("can not connect mysql error...(enterprise.domain)\n");
return 0;
}
if(!(sock2 = mysql_real_connect( &myData2, mysqlServer, user, password, database2,port,NULL,0)))
{
printf("can not connect mysql error...(enterprisemail.domain)\n");
return 0;
}
//读取文本
ifstream fin(file_path);
ofstream fout1(file_path1,ios_base::app);//enterprise.domain的数据库select语句成功日志
ofstream fout2(file_path2,ios_base::app);//enterprise.domain的数据库select语句失败日志
ofstream fout3(file_path3,ios_base::app);//enterprisemail.domain数据库的update修改成功日志
ofstream fout4(file_path4,ios_base::app); //enterprisemail.domain数据库的update语句修改失败日志
ofstream fout5(file_path5,ios_base::app); //enterprisemail.domain数据库的update语句修改失败日志
string str;
while(getline(fin,str))
{
trim(str);//去掉读出的一行前后空格
char buffer[1024];
int str_to_int=atoi(str.c_str());
sprintf(buffer,"%d",str_to_int);
if(strcmp(str.c_str(),buffer)!=0)
{
cout <<str<<"Have contain special character in one line,please check...\n";
fout2 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<< "Enterpriseid:\t" <<str <<"\tHave contain special character in one line,please check...\n";
continue;
}
memset(buffer,0,1024);//销毁临时变量
//判断是否是数字
if (!str.length())
{
printf("请检查一下你的./ent_list里面是否有空行...\n");
return 0;
}
strcpy(query,"select name from `domain` where name not like \"%shenbak\" and enterpriseid=");
strcat(query,str.c_str());
cout<<query<<"\n";
if( mysql_query(&myData, query) != 0 )
{
fout2 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<< "Enterpriseid:\t" <<str <<"\t Failed!\n"; //失败的select 查询记录到日志enterprise.domain.failed.log
continue;
}else{
res = mysql_store_result( &myData);
while(row = mysql_fetch_row(res))
{
fout1 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<<"Enterpriseid:\t" << str <<"\tname:\t" << row[0] <<"\t Select sql Run Successful!\n";//写日志
strcpy(name,row[0]);
if(flag==0)
{
strcpy(query2,"update\t`domain` set name=replace(name,name,concat(name,\"shenbak\")) where name not like \"%shenbak\" and name=");
strcat(query2,"'");
strcat(query2,name);
strcat(query2,"'");
cout << query2<<"\n";
}
if(flag==1)
{
strcpy(query2,"update `domain` set name=replace(name,\"shenbak\",\"\") where name like \"%shenbak\" and name=");
strcat(query2,"'");
strcat(query2,name);
strcat(query2,"shenbak");
strcat(query2,"'");
}
if( mysql_query(&myData2, query2) != 0 )
{
fout4 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<< "Enterpriseid:\t" << str <<"\tname:\t"<<name<<"\tupdate query failed!\n";
continue;
}else{
if(flag==0)
{
fout3 << x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<<"Enterpriseid:\t" << str << "\tname:\t" <<name<<"\tupdate query successful!\n";
//写屏蔽日志
}
if(flag==1)
{
fout5 <<x->tm_year+1900 <<"年"<<x->tm_mon+1<<"月"<<x->tm_mday<<"日"<<x->tm_hour<<"点"<<x->tm_min<<"分"<<x->tm_sec<<"秒\t"<<"Enterpriseid:\t" << str << "\tname:\t" <<name<<"\tupdate query successful!\n";
//写日恢复日志
}
}
memset(name,0,1024);
}
str="";
memset(query,0,1024);
memset(query2,0,1024);
}
}
mysql_free_result(res);
mysql_close(&myData);
mysql_close(&myData2);
fin.close();
fout1.close();
fout2.close();
fout3.close();
fout4.close();
fout4.close();
cout << "\nAll task run ok....Goodbye!\n";
}
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/957/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表