tail

Tailing a binary file in Erlang adds mysterious bit-string

I want to run tail on a named pipe to facilitate some binary logfile processing. The problem is that mysterious data is being added to the beginning of the stream. I run my tests by starting the erlang process with the opened port (open_port) and then I use another shell to cat the bin into the named pipe. Here is a simple function for ...

Java Scanner won't follow file

Trying to tail / parse some log files. Entries start with a date then can span many lines. This works, but does not ever see new entries to file. File inputFile = new File("C:/test.txt"); InputStream is = new FileInputStream(inputFile); InputStream bis = new BufferedInputStream(is); //bis.skip(inputFile.length()); Scanner src = new Sca...

Bash edit file and keep last 500 lines

I am looking to create a cron job that opens a directory loops through all the logs i have created and deletes all lines but keep the last 500 for example. I was thinking of something along the lines of tail -n 500 filename > filename Would this work? I also not sure how to loop through a directory in bash Thanks in advance. ...

Tailing 'Jobs' with Perl under mod_perl

Hi everyone, I've got this project running under mod_perl shows some information on a host. On this page is a text box with a dropdown that allows users to ping/nslookup/traceroute the host. The output is shown in the text box like a tail -f. It works great under CGI. When the user requests a ping it would make an AJAX call to the serv...

Why does fgets(STDIN, 1024) not work anymore?

Question 1 I used to use that line for my PHP parser file for a game server, but it does not work anymore. I know there is the fopen("php://stdin") thing but that's now 3 lines of code instead of just one, why would PHP do this? Question 2 Also, when I use that method I keep getting this output which is causing my script to not read t...

Best way to split several heads from a list with Erlang?

So, Erlang is a real joy to work with, but there's one problem I run into occasionally, that I'm wondering if there is a nicer way to solve. Often, I find myself needing to split several items from a list. The syntax for splitting a list into a Head and Tail is straight forward enough, but what about when there are multiple items. 1> Li...

How do I process captured output from `tail` without reprocessing?

Hi, I want to excecute a tail command in Unix for indefinite time and capture its output in a Perl script, process it and store certain data into a database. But it should be live, meaning old data – once stored in the database – shouldn't be reprocessed. It should only capture, and process only the most recent output. Can someone pleas...

How to tail -f the latest log file with a given pattern

Hello, I work with some log system which creates a log file every hour, like follows: SoftwareLog.2010-08-01-08 SoftwareLog.2010-08-01-09 SoftwareLog.2010-08-01-10 I'm trying to tail to follow the latest log file giving a pattern (e.g. SoftwareLog*) and I realize there's: tail -F (tail --follow=name --retry) but that only follow o...

Monitoring/highlighting terminal stdout for keywords

Because our recent development work, I was put into a position where I have to monitoring a few of our application's output logs, specifically I am looking for a certain error code(s). Because my limited scripting skill right now the only thing I can do is to tail -f the log file and just keep looking for update. I also use PuTTY. I am h...

alternative to tail -F

Hi, I am monitoring a log file by doing "TAIL -n -0 -F filename". But this is taking up a lof of CPU as there are many messages being written to the logfile. Is there a way, I can open a file and read new/few entries and close it and repeat it every 5 second interval? So that I don't need to keep following the file? How can I remember t...

Minimum Websocket Nodejs Tail Example

I'm trying to create a stream of data to the browser using websocket. The data is the output of a log file. (tail -f filename) Using node js, I've manage to log into stdout, but I haven't been able to create the server and create the client (js/html) code to create a websocket and receive all the output of this child process. Can anyone ...

How do I execute a Perl program on a remote machine?

I wrote a Perl program to capture a live data stream from a tail command on a Linux machine using the following command in the console: tail -f xyz.log | myperl.pl It works fine. But now I have to execute this Perl program on a different machine because the log file is on that different machine. Can anyone tell me how I can do it? ...

What's the opposite of head? I want all but the first N lines of a file.

Given a text file of unknown length, how can I read, for example all but the first 2 lines of the file? I know tail will give me the last N lines, but I don't know what N is ahead of time. So for a file AAAA BBBB CCCC DDDD EEEE I want CCCC DDDD EEEE And for a file AAAA BBBB CCCC I'd get just CCCC ...

tail -f using PuTTY hangs

I am using PuTTY command line to connect to a server and tail a log file. On local machine I've created a file "tail-exec" which contains following text: tail -f /var/log/test.log I am starting putty through command line as: putty -ssh -t -pw -m tail-exec user@server This opens up the terminal window with log tail. But the problem i...

Detecting a File Delete on an Open File

I am opening a file with read access and allowing subsequent read|write|delete file share access to the file (tailing the file). If the file is deleted during processing is there a way to detect that the file is pending delete (see Files section http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx)? If some outside process (the...

Is there an equivalent of `tail -f` in Perl?

I'm writing a script that listens for changes to a log file and acts appropriately. At the moment I'm using open my $fh, "tail -f $logfile |"; but ideally I don't want to use system calls. I've tried File::Tail but it has a minimum interval of 1 second (I've tried passing less but it defaults to 1 second, even if I pass 0). I've check...

How can I remove all but the last 10 lines from a file?

Is it possible to keep only the last 10 lines of a lines with a simple shell command? tail -n 10 test.log delivers the right result, but I don't know how to modify test.log itself. And tail -n 10 test.log > test.log doesn't work. ...

tail file - count number of lines with a given pattern

Hi. I need to guarantee that a specific string is appearing in an active log file, meaning an operation is alive (feeding this count to a Trigger). Considering I'll do this remotely, I can't go with 'tail -f filename' else it would follow the file indefinitely, thus I'm thinking about grabbing a bunch of last written lines and countin...

Haskell tail-recursion performance question for Levenshtein distances

I'm playing around with calculating Levenshtein distances in Haskell, and am a little frustrated with the following performance problem. If you implement it most 'normal' way for Haskell, like below (dist), everything works just fine: dist :: (Ord a) => [a] -> [a] -> Int dist s1 s2 = ldist s1 s2 (L.length s1, L.length s2) ldist :: (Or...

Displaying log data in latest-first format

I like having log data in a last-first form (the same way most blogs and news sites organize their posts). The languages I'm most comfortable in are C++ and Python: is there a way to output log data either to the screen (stdout) or a file with the most recent entry always being on top? Or is there perhaps a way of modifying tail to sho...