先是idea的jar包
点击ok appaly
下一步点开
选择你刚才点的jar包点build
然后打包完成 上传至linux
我选择的是rz直接上传,没有的可以直接使用命令
yum install -y lrzsz
下载此插件
运行jar包命令
java -jar xxx.jar "参数" "参数" 我的代码块需要三个参数 这是我的执行命令 fileReadRunnable.run(args[0],args[1],args[2]); java -jar filter_ips.jar "004_20220121.log" "/root/jar/004.txt" "20220121"
注意 传参 参数需要用引号括起来
package com.zte.runnable; import com.zte.utils.MySQLJDBC; import com.zte.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; public class FileReadDataRunnable { //check 返回ip和一堆true private static Logger logger = LoggerFactory.getLogger(FileReadDataRunnable.class); private static SimpleDateFormat s = new SimpleDateFormat("yyyyMMdd"); // private JdbcTemplate jdbcTemplate; // public FileCountRunnable(JdbcTemplate jdbcTemplate) { // this.jdbcTemplate = jdbcTemplate; // } public void run(String inputpath,String outputpath,String filterDate) { BufferedReader reader = null; BufferedReader readersql = null; String line = null; String linesql = null; Connection conn = null; try { conn = MySQLJDBC.getConnection(); } catch (SQLException e) { e.printStackTrace(); } try { StringBuffer buffer = new StringBuffer(); String ip = ""; boolean isFlume = false; boolean is001 = false; boolean is002 = false; boolean is004 = false; boolean isConnect = false; boolean isFlumeOk = false; // 清洗check的log // reader = new BufferedReader(new FileReader("D:\日志\filter_data (2)\input\check" + filterDate +".log")); reader = new BufferedReader(new FileReader("" + inputpath)); while ((line = reader.readLine()) != null) { // line = StringUtils.deleteWhitespace(line); if (line.contains("-begin-")) { // 开启新一轮统计 ip = ""; isFlume = false; is001 = false; is002 = false; is004 = false; isConnect = false; isFlumeOk = false; continue; } if (line.contains("-over-")) { // 开启新一轮统计 // logger.info("连接状态:{},ip地址:{}",isOk,ip); buffer.append(ip).append(",").append(isConnect).append(",").append(isFlume).append(","). append(isFlumeOk).append(",").append(is001).append(",").append(is002).append(",").append(is004).append("n"); continue; } if (line.contains("process_data_daily.sh")) { isFlume = true; } if (line.contains("pass") && line.contains("001_") && line.contains("json")) { is001 = true; } if (line.contains("pass") && line.contains("002_") && line.contains("json")) { is002 = true; } if (line.contains("vlpr") && line.contains("004_") && line.contains("json")) { is004 = true; } if (line.contains("home") && line.contains("mjxt") && line.contains("bash_logout")) { isConnect = true; } if (line.contains("home") && line.contains("mjxt") && line.contains("flume_data")) { isFlumeOk = true; } if (line.startsWith("ip=")) { logger.info(line.split(" ")[1]); ip = line.split(" ")[1]; } } // writeFile("D:\日志\filter_data (2)\output\ipCount" + filterDate + ".txt", buffer.toString()); writeFile("" + outputpath, buffer.toString()); System.out.println("-----------------------------"); logger.info("开始插入数据"); // reader = new BufferedReader(new FileReader("D:\日志\filter_data (2)\output\ipCount" + filterDate + ".txt")); reader = new BufferedReader(new FileReader("" + outputpath)); while ((linesql = reader.readLine()) != null) { String[] split = linesql.split(","); String ipaddress = split[0]; String status = split[1]; String flumeStatus = split[2]; String stock = split[3]; String type001 = split[4]; String type002 = split[5]; String type004 = split[6]; // ArrayLists1 = new ArrayList<>(); // s1.add(buffer.toString()); // 获取数据库连接 String insertSQL = "insert into mjcheck (ipaddress,status,flumeStatus,stock,type001,type002,type004,pt) values" + "(?,?,?,?,?,?,?,?) "; PreparedStatement statement = conn.prepareStatement(insertSQL); statement.setString(1,ipaddress); statement.setString(2,status); statement.setString(3,flumeStatus); statement.setString(4,stock); statement.setString(5,type001); statement.setString(6,type002); statement.setString(7,type004); statement.setString(8,filterDate); // statement.setDate(8, java.sql.Date.valueOf(filterDate)); statement.execute(); } conn.close(); } catch (Exception e) { logger.error("格式化错误", e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } } public void writeFile(String fileName, String value) throws Exception { File ff = new File(fileName); if (!ff.exists()) { ff.getParentFile().mkdirs(); ff.createNewFile(); } FileOutputStream fs = new FileOutputStream(ff); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fs)); writer.write(value); writer.close(); } public static void main(String[] args) { FileReadDataRunnable fileReadRunnable = new FileReadDataRunnable(); // 获取时间 为后面的数据插入指定时间 // Date date = new Date(); // Calendar cal = Calendar.getInstance(); // cal.setTime(date); // // 可以选择前一天或者后一天 // cal.add(Calendar.DATE,-0); // SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); // String filterDate = format.format(cal.getTime()); // fileReadRunnable.run(filterDate); // 0是输入路径 1是输出路径 2是指定时间 fileReadRunnable.run(args[0],args[1],args[2]); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)