tail

Improvements to this bash script to simulate “tail --follow”

回眸只為那壹抹淺笑 提交于 2019-12-05 19:34:09
I need to remote tail log files such that the tailing continues working even when the file is rolled over. My attempts to do so, started by directly using the tail command over ssh: ssh root@some-remote-host tail -1000f /some-directory/application.log | tee /c/local-directory/applicaiton.log That allows me to filter through /c/local-directory/applicaiton.log locally using Otroslogviewer (which was the original purpose of trying to tail the log file locally). The above stops tailing when the remote log file is rolled over (which happens at every 10MB). I do not have the access required to

Run tail -f for a specific time in bash script

不想你离开。 提交于 2019-12-05 17:42:04
I need a script that will run a series of tail -f commands and output them into a file. What I need is for tail -f to run for a certain amount of time to grep specific words. The reason it's a certain amount of time is because some of these values don't show up right away as this is a live log. How can I run something like this for let's say 20 seconds, output the grep command and then continue on to the next command? tail -f /example/logs/auditlog | grep test Thanks timeout 20 tail -f /example/logs/auditlog | grep test tail -f /example/logs/auditlog | grep test & pid=$! sleep 20 kill $pid

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

喜夏-厌秋 提交于 2019-12-05 13:37:45
问题 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. 回答1: You can do it using tempfile. tail -n 10 test.log > test1.log mv test1.log test.log 回答2: echo "$(tail -n 10 test.log)" > test.log Quotes are important. They preserve newline characters. 回答3: Invoke ed command (text editor): echo -e '1,-10d\nwq' | ed <filename>

How to follow a (changing) log file in node.js

时光总嘲笑我的痴心妄想 提交于 2019-12-05 12:43:53
OK this might appear to be an easy question but I couldn't find the answer from here so I am posting it in hope someone might have encountered the similar problem. I need to monitor a symlink which points to a web server file ( /var/log/lighttpd/error.log to be more specific, thanks to Linus G Thiel I figured out how to follow symlinks ). I know I can set up fs.fileWatch to monitor it but I should also point out that the error.log file also got rotated at a specific time, depending on whatever the log daemon settings are. When that happens, fs.fileWatch stops working. I also know I can spawn a

Tail a text file on a web server via HTTP

被刻印的时光 ゝ 提交于 2019-12-05 08:14:18
Looking for input on how to solve the following problem. My ColdFusion 9 app has a simple logger that writes text to a file. On my dev machine, the file is local so I can use either 'tail -f' or CFB's TailView to watch it. I'd like a tool to watch it when it's deployed on the production server. The catch: production is at a shared CF hosting provider which doesn't allow RDS file access or a directory-watcher gateway. I'm wondering about a page with a meta refresh tag or if I want to get more fancy, something AJAXy to the same effect. Thoughts? Any tools that already exist for this? I may

Java “tail -f” wrapper

核能气质少年 提交于 2019-12-05 02:23:56
问题 I need to wrap the Unix command "tail -f" in a BufferedInputStream. I don't want to simulate or mimic tail as stated by this question. Rather, I want to use tail, waiting for it to give me a new line. 回答1: Your best bet is to use the Process class and read with a Scanner : Runtime r = Runtime.getRuntime() Process p = r.exec("tail -f") Scanner s = new Scanner(p.getInputStream()) while (s.hasNextLine()) { String line = s.nextLine() // Do whatever you want with the output. } hasNextLine() should

How do I use Head and Tail to print specific lines of a file

坚强是说给别人听的谎言 提交于 2019-12-04 23:42:03
I want to say output lines 5 - 10 of a file, as arguments passed in. How could I use head and tail to do this? where firstline = $2 and lastline = $3 and filename = $1 . Running it should look like this: ./lines.sh filename firstline lastline sfstewman Aside from the answers given by fedorqui and Kent , you can also use a single sed command: #! /bin/sh filename=$1 firstline=$2 lastline=$3 # Basics of sed: # 1. sed commands have a matching part and a command part. # 2. The matching part matches lines, generally by number or regular expression. # 3. The command part executes a command on that

Tailing Rolling Files

扶醉桌前 提交于 2019-12-04 16:28:03
问题 I have a directory full of rolling log files that I would like to be able to use tail on. The files are named as such: name modified 00A.txt Dec 27 19:00 00B.txt Dec 27 19:01 00C.txt Dec 27 19:02 00D.txt Dec 27 19:03 On an older unix system, I'm trying to come up with a shell script that will tail the most recently modified file in a specific directory, and if that file gets administratively closed (rolls to the next file) I want the program to automatically begin tailing the new file without

combining head and tail methods in R

大城市里の小女人 提交于 2019-12-04 11:12:16
I use the head(d) and tail(d) methods in R package utils a lot - frequently one after the other. So i wrote a simple wrapper for the two functions: ht <- function(d, m=5, n=m){ # print the head and tail together cat(" head --> ", head(d,m), "\n", "--------", "\n", "tail --> ", tail(d,n), "\n") } And i got some unexpected results ... can someone please help me understand why? (so i can fix it ... or at least understand your solution!). Some background... Numeric is fine: x <- 1:100 ht(x) As is complex: ni <- as.complex(1:100) ht(ni) and character: ll <- letters[1:26] ht(ll) Matrix loses it's

Tail -n 1000 in Java (Apache commons, etc)

一世执手 提交于 2019-12-04 10:15:40
I'm wondering if util code already exists to implement some/all of *NIX tail. I'd like to copy the last n lines of some file/reader to another file/reader, etc. This seems like a good bet: Tailer Library . This implementation is based on it, but isn't the same. Neither implement a lookback to get the last 100 lines though. :( You could take a look at this tail implementation in one of Heritrix 's utility classes. I didn't write it but I wrote the code that uses it, works correctly as far as I can tell. This is a UI app - you can look at the source though to see what it does (basically some