Hello everybody, I'm currently watching my log files like this tail -f
and every now and then I press up key and hit return so new changes in log print into console, how to make it print itself when change in log file occur? Here is the requirement :
START loop
1. Check file.log
2. If file.log has changed print the changes
3. else print nothing
END
I wrote something similar for windows to execute from java :
import java.io.FileInputStream;
import java.io.DataInputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
class LogWatch {
public static void main(String args[]) {
try {
FileInputStream fstream = new FileInputStream("C:\\file.log");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
while (true) {
line = br.readLine();
if (line == null) {
Thread.sleep(500);
} else {
System.out.println(line);
}
}
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
Which is unnecessary overhead, because this can be done from shell script, does anyone have any suggestions how to do it ?