tail

pipe tail output into another script

允我心安 提交于 2019-12-03 03:53:55
I am trying to pipe the output of a tail command into another bash script to process: tail -n +1 -f your_log_file | myscript.sh However, when I run it, the $1 parameter (inside the myscript.sh) never gets reached. What am I missing? How do I pipe the output to be the input parameter of the script? PS - I want tail to run forever and continue piping each individual line into the script. Edit For now the entire contents of myscripts.sh are: echo $1; Generally, here is one way to handle standard input to a script: #!/bin/bash while read line; do echo $line done That is a very rough bash

Apply formatting to unix shell

喜夏-厌秋 提交于 2019-12-03 01:25:13
I've been looking at some server logs using tail -f recently, and have thought that it'd be much easier to see some things if I could format the output. Really all I'm looking for is a way to perhaps colour certain words (determined by a regex), and perhaps remove certain words (again, determined by a regex). I know there's programs which visualize server logs in real time and whatnot, but I'm more interested in this. Pipe the output of tail -f into sed , and add in some ANSI escape codes . For example, the following will colorize all numbers in red (color 31) and all quoted strings in bright

how to continuously display a file of its last several lines of contents

自闭症网瘾萝莉.ら 提交于 2019-12-02 20:37:36
I am trying to find a Unix command (combination, maybe) on how to continuously display a file of its last several lines of contents. But during this displaying, I want some of the top lines are always displayed on the screen top when the rolling contents reach the screen top. Is that possible? (1) Suppose I have file, "job.sta", the first 2 lines are: job name, John's job on 2013-Jan-30,... Tab1, Tab2, Tab3 0, 1, 2, 1, 90, 89 2, 89, 23 ... (2) This file is on its running, its contents are growing, and I don't know what line it's going to end. (3) So I want to display (always) the first 2 lines

Java RandomAccessFile.java under linux not working correctly

非 Y 不嫁゛ 提交于 2019-12-02 06:54:08
Im trying to implement the simple tail -f linux command in java. Here is my code. try { // position within the file File file = new File("/home/curuk/monitored/log.txt"); RandomAccessFile raFile = new RandomAccessFile(file, "r"); long last = file.lastModified(); // The last time the file was checked for changes long position = file.length(); while (true) { if (file.lastModified() > last) { last = file.lastModified(); readFromFile(raFile, (int) position, (int) (file.length() - position)); position = file.length(); } Thread.sleep(1000); } } catch (IOException e) { e.printStackTrace(); } private

Batch file to output last line of findstr

天大地大妈咪最大 提交于 2019-12-02 04:15:51
I am trying to find a list of machines in files in folders, and print out the last line of the output only. @echo off for /f %%a in (computers.txt) do findstr /xs "%%a" unhealthy.txt pause The computers.txt file has a list of 300 machines. I want that to output only the last line of each instance it finds. Right now the command displays and outputs all instances of the computer name, not just the tail end. I've tried to use "tail for Windows" but am getting errors as well. Current output: 2013\10-Oct\28\unhealthy.txt:WIN57505 2013\10-Oct\29\unhealthy.txt:WIN57505 2013\10-Oct\30\unhealthy.txt

Implement tail with awk

牧云@^-^@ 提交于 2019-12-01 23:29:40
问题 Alright so here i am struggling with this awk code wich should emulate the tail command num=$1; { vect[NR]=$0; } END{ for(i=NR-num;i<=NR;i++) print vect[$i] } So what i'm trying to achieve here is an tail command emulated by awk for example consider cat somefile | awk -f tail.awk 10 shoud print the last 10 lines of a text file,any suggestions ? 回答1: for(i=NR-num;i<=NR;i++) print vect[$i] $ indicates a positional parameter. Use just plain i : for(i=NR-num;i<=NR;i++) print vect[i] The full code

Flume-ng tail a file

爷,独闯天下 提交于 2019-12-01 14:08:20
I am trying to understand how to tail a file with flume-ng so that I can push the data into HDFS. In the first instance I have setup a simple conf file: tail1.sources = source1 tail1.sinks = sink1 tail1.channels = channel1 tail1.sources.source1.type = exec tail1.sources.source1.command = tail -F /var/log/apache2/access.log tail1.sources.source1.channels = channel1 tail1.sinks.sink1.type = logger tail1.channels.channel1.type = memory tail1.channels.channel1.capacity = 1000 tail1.channels.channel1.transactionCapacity = 100 tail1.sources.source1.channels = channel1 tail1.sinks.sink1.channel =

Flume-ng tail a file

天涯浪子 提交于 2019-12-01 11:06:24
问题 I am trying to understand how to tail a file with flume-ng so that I can push the data into HDFS. In the first instance I have setup a simple conf file: tail1.sources = source1 tail1.sinks = sink1 tail1.channels = channel1 tail1.sources.source1.type = exec tail1.sources.source1.command = tail -F /var/log/apache2/access.log tail1.sources.source1.channels = channel1 tail1.sinks.sink1.type = logger tail1.channels.channel1.type = memory tail1.channels.channel1.capacity = 1000 tail1.channels

Java web application that can stream the content of an arbitrary file to the browser (live tail)

半城伤御伤魂 提交于 2019-12-01 09:19:53
问题 I have been searching the web for a while for a Java web application that can be used to "tail" on any arbitrary file on the file system. The most important requirement would be to have the app to stream back the file changes so that I don't have to refresh (like the stuff you can easily do with node.js). I can quickly write one myself but the streaming requirement is not trivial. Also, the app should be deployable in a Java app server. Any pointer? Thanks 回答1: Ok, so I followed @Liv

How to pipe tail -f into awk

眉间皱痕 提交于 2019-12-01 05:46:55
I'm trying to set up a script where an alert is generated when a certain string appears in a log file. The solution already in place greps the whole log file once a minute and counts how often the string appears, using the log line's timestamp to count only occurrences in the previous minute. I figured it would be much more efficient to do this with a tail, so I tried the following, as a test: FILENAME="/var/log/file.log" tail -f $FILENAME | awk -F , -v var="$HOSTNAME" ' BEGIN { failed_count=0; } /account failure reason/ { failed_count++; } END { printf("%saccount failure reason (Errors per