public class Objectouttest {
* Write object to file method */
public void write (Object o, String path) {
try {
/* Create Access file */
FileOutputStream FileStream = new FileOutputStream (path);
/* Write the Access file to the object */
ObjectOutputStream OS = new ObjectOutputStream (fileStream);
/* Write to Object */
Os.writeobject (o);
System.out.println ("Write Data Success");
/* Close ObjectOutputStream */
Os.close ();
} catch (FileNotFoundException e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
// }
//}
* Read the object out of the file */
public void Read (String path) {
try {
/* Connect to the file you want to read */
FileInputStream FileStream = new FileInputStream (path);
/* How to read the attached file */
ObjectInputStream OS = new ObjectInputStream (fileStream);
/* Read Object */
Logobject dog = (logobject) os.readobject ();
SYSTEM.OUT.PRINTLN ("Output result:" + dog.getfrom () + "is a"
+ dog.getip () + ", High:" + dog.geturl () + ", Long:");
/* Close Object */
Os.close ();
} catch (FileNotFoundException e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
} catch (ClassNotFoundException e) {
E.printstacktrace ();
// }
//}
/* Write a string to the file */
public void wirtestring (string path, string context) {
try {
/* Create a Write Object */
FileWriter FileWriter = new FileWriter (path,true);
/* Create buffer */
BufferedWriter writer = new BufferedWriter (fileWriter);
/* Write String */
Writer.write ("\ n" +context);
/* Turn off the object */
Writer.close ();
System.out.println ("Write String succeeded! ");
} catch (IOException e) {
E.printstacktrace ();
}
}
/* Read the string in the file */
public void readString (String path) {
try {
/* Create read Object */
FileReader FileReader = new FileReader (path);
/* Create a buffer */
BufferedReader reader = new BufferedReader (FileReader);
/* Read File */
String line = null;
while (line = Reader.readline ()) = null) {
String s[]=line.split ("");
String str1= "";
for (int i=0;i<s.length;i++) {
if (i==0| | i==3| | i==6| | i==10) {
if (i==0) {
str1+= "IP:" + "--" +s[i]+ "";
}
if (i==3) {
str1+= "Access time:" + "--" +s[i]+ "";
}
if (i==6) {
str1+= "URL:" + "--" +s[i]+ "";
}
if (i==10) {
if (S[10].contains ("baidu.com")) {
str1+= "Outside the station (Baidu Bidding):" + "--" +s[i]+ ";
}else{
str1+= "Internal:" + "--" +s[i]+ "";
}
}
Internal Baidu bidding direct access outside the station
}
System.out.println (STR1);
}
if (S[6].contains (". jpg") | | S[6].contains (". png") | | S[6].contains (". ico") | | S[6].contains ("/app/api") | | S[6].contains (". gif") | | S[6].contains (". css") | | S[6].contains (". js")) {
}else{
Objectouttest QQT = new Objectouttest ();
Date Date=new date ();
SimpleDateFormat sdf=new SimpleDateFormat ("Yyyy-mm-dd");
String S1=sdf.format (date);
Qqt.wirtestring ("/home/data/htdocs/web/log/" +s1+ ". csv", str1);
}
}
/* Close Object */
Reader.close ();
} catch (FileNotFoundException e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
}
/* Exit Function Entry */
public static void Main (String args[]) {
Objectouttest QQT = new Objectouttest ();
Date Date=new date ();
SimpleDateFormat sdf=new SimpleDateFormat ("Yyyy-mm-dd");
String S=sdf.format (date);
Qqt.readstring ("/home/logsplit/" +s);
}
}
Write the method to generate the jar package, put the jar package on the line, and write a script to run the jar package.
cd/home/timer/
Export JAVA_HOME=/OPT/JDK7
Export classpath=.: $CLASSPATH:/home/timer/rizhijiexi.jar:
Export path= $JAVA _home/bin: $PATH
java-xms256m-xmx512m com. Objectouttest >>/home/logsplit/objectout.log &
Put the run script file under/opt/shell
And then
command to insert a timed startup script by running Crontab-e and then entering O
Web site logs are parsed and a readable file is generated