I want to read this file (preferably only the last 10ish lines or so) to check that the mail server at least tried to send out an email after I performed an action somewhere else. I know how I'd do it if the file were local, and if I knew the file wouldn't be accessed while I was reading it, but I was hoping there would be a clean and simple way to do it, such as reading the output of a tail -f command (yeah, I'm on *nix).
Using file access requires that you do in fact have file access to the file.
If you do then you can use the java.io classes to access the file without using tail. However you would be implementing the same functionality that exists in there and perhaps in a less efficient manner that used by tail.
If you don't have file access then you can't do anything in java until you figure out what kind of access you do have.
I have SU access, it's just another step in the process, and I say it here because I'm also not entirely sure how to yank it off the server. I was thinking of just copying it over to my local machine before dealing with it, maybe to decrease traffic flow, and definitely because I honestly don't feel comfortable messing with files on the SMTP server with SU access (I could really screw something up!).
But I digress... I mention it because I don't know exactly how I'd pull it off of the server, other than to execute a system command in Java like
"scp bouncey.bounce.net:/path/to/file myDesktop:/where/to/put/it"
or something (I may have screwed up the syntax on that, but that's neither here nor there).
Is there a clean way to do even that, or should I just not worry about it, as long as my stream is pointing the right way?
JSch ([http://www.jcraft.com/jsch/|http://www.jcraft.com/jsch/]) is a more sane way to do a programmatic ssh/scp programmatically within Java, but I'm not certain that it's the most efficient way to do log analysis here.
Then again, you could use it to do a type of periodic
Yeah, I really don't want to do that either, but I'm not really sure what else to do.
I found this floating around on Google:
this looks like what I'm trying to do, I think?
EDIT: I think I'm going to pursue my path for a while, but if it doesn't end well (and it may, this FileFollowingPane thing looks pretty complicated) I'll try our that thing you linked. I'll post again with an update, in case someone else comes upon this problem.
Edited by: tomthemage on Jun 17, 2008 11:29 AM
Seems like there are two problems in the above.
- You want to access only a copy.
- You want to process a log file.
The first of course requires that you have a copy. Again with file access you can do that via java. And again if you don't have file access then you must first determine the method that does allow access (outside of java) before addressing it in java. And if that means ssh then you will need to use it.
Once you have a local copy as a file then you can use java.io to process it. Note that parsing server log files is a rather standard activity and you might want to look for existing solutions before rolling your own.