Tail -f Command help


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Tail -f Command help
# 1  
Old 11-29-2018
Tail -f Command help

Hi Team,

Can anyone help me here:
I have to access server logs via putty and these logs file is a trailing file (continously updating) with ERROR and WARNINGS... I need to know if I can pull this trailing file to a local drive so that I can do some higlighting on some keywords through Notepad ++

But I need to manipulate data in real-time (not on the archived file)... Also, I don't have write access on the server as well, so cannot write logs to new file on the server.

Please help !
# 2  
Old 11-29-2018
I do not know how to automate notepad++ on UNIX remote files.
However, the rest is doable. I'm not giving the best possbile answer because I cannot do that without knowing your system type and your shell.
1. you need to be able to login in to the server
2. you have to be able to write to a file in your home directory or /tmp

Some flavors of Linux example:
Code:
$ sudo apt-get install sshpass   # do this only once
$ sshpass -p your_password ssh user@hostname 'tail -f /path/to/logfile/filename ' > $HOME/somefile  &

The & makes the command run in the background
$HOME/somefile will have the data you want work with
Note that you need to be very specific about what you want to find locally. Please. Give us example input and desired ouput. Also!
Please give us the output of:

uname -a && echo $SHELL

My example DOES NOT work everywhere.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 11-29-2018
Quote:
Originally Posted by jim mcnamara
I do not know how to automate notepad++ on UNIX remote files.
However, the rest is doable. I'm not giving the best possbile answer because I cannot do that without knowing your system type and your shell.
1. you need to be able to login in to the server
2. you have to be able to write to a file in your home directory or /tmp

Some flavors of Linux example:
Code:
$ sudo apt-get install sshpass   # do this only once
$ sshpass -p your_password ssh user@hostname 'tail -f /path/to/logfile/filename ' > $HOME/somefile  &

The & makes the command run in the background
$HOME/somefile will have the data you want work with
Note that you need to be very specific about what you want to find locally. Please. Give us example input and desired ouput. Also!
Please give us the output of:

uname -a && echo $SHELL

My example DOES NOT work everywhere.
Thanks @Jim for the answer.
I'm a beginner and may not know everything about UNIX commands. My question was just that if there's any way we can download any file to my local system from Putty/WinSCP and that file is in continous update mode (logs are getting written everytime on that file).

I need to highlight ERROR word with red color in that file.
Normally I use tail -f server.log to follow this file, and keep a eye to see for ERROR line. I just want a better UI so that ERROR lines is visible easily.
# 4  
Old 11-29-2018
Do you have access to cron / crontab on the remote system?
This User Gave Thanks to RudiC For This Post:
# 5  
Old 11-29-2018
You can probably do this in your terminal by printing an escape sequence to change color (and another after, to reset it to normal). 1;31 means bold+red, 0 means reset. See this list for other colors.

Code:
$ tail -f file | awk '/ERROR/ { $0="\x1b[1;31m" $0 "\x1b[0m"; } 1'

text
text
text
something something ERROR something something
text
text
text

You may even be able to make your computer beep from your terminal, as there's a special nonprinting character \a just for that:
Code:
$ tail -f file | awk '/ERROR/ { $0="\a\x1b[1;31m" $0 "\x1b[0m"; } 1'

text
text
text
something something ERROR something something
text
text
text

These 2 Users Gave Thanks to Corona688 For This Post:
# 6  
Old 11-29-2018
Yes, I do have the access to crontab command.

------ Post updated at 03:40 AM ------

Thanks for the help @Crona688 It works like a charm.
It fulfills my problem to an extent.

I would me more happy if I can pull the server.log file to my local Windows directory and it should be updating continously as it do on the server. Can you tell if there's any way to sync/download the file to local drive while it is continoulsy updated on the server path.

Thanks for the help always !

Last edited by Don Cragun; 11-30-2018 at 01:24 AM.. Reason: Remve duplicated post.
This User Gave Thanks to jitensetia For This Post:
# 7  
Old 11-30-2018
Please show us the code you are using now. We especially need to see how you are accessing the remote file.

If you can directly access the file on the remote server, do you actually need a copy of the file on your Windows system, or do you just need to see new entries as they are added to the file on the remote server?

Trying to keep a local copy of a file synchronized with a continuously changing remote file can be tricky if you can't use tail -f /remote/file/pathname. You you can directly access /remote/file/pathname from your Windows server, tail should be all you need to keep with with changes being added to the file on the remote server and should also be able to keep a local copy of the file up-to-date with text appended to that file on the remote system.

If existing text in the remote file is being modified while additional text is being appended to the end of the file, your problem is MUCH more complicated than you have implied so far.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. How to Post in the The UNIX and Linux Forums

Usage of tail command in .awk

Hi, I want to do file format using awk script, for that i wan to use 'tail'. Here is the scenario. I will be having set of files in a directory. Those files i need to write to another directory with same file name, but while writing the file to out directory, i need to write the last line as... (3 Replies)
Discussion started by: Venkata Madhu
3 Replies

2. Homework & Coursework Questions

Using tail with the filter command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Devise a chain of filters using some or all of the following programs pr, cut, cat, tail to display a numbered... (8 Replies)
Discussion started by: hbell221
8 Replies

3. Shell Programming and Scripting

tail command help

Hi does anyone know how to create a file using the tail command? My book has this file I need to create and it says to use the tail command and that it is possible but I have no idea. Thanks. (4 Replies)
Discussion started by: drew211
4 Replies

4. Shell Programming and Scripting

tail command problems

Hi, In my home directory, there are so many files. i tried to get the lastly created file by following command. file=`ls -lrt MXOfiles* | tail -1` As there are so many files, it displays "$ : 0403-027 The parameter list is too long." Can someone tell me how can i get the recent file... (1 Reply)
Discussion started by: JSKOBS
1 Replies

5. UNIX for Dummies Questions & Answers

Tail command with wildcard file name

Please help with the following command tail -f /appdata/logs/alert_audit517.txt | grep "Sep 02" The problem I have is with the file name "alert_audit517.txt". The 3 digit number at the end of the file name changes, so I need the file name to use a wildcard. Ive tried alert_audit***.txt, but... (5 Replies)
Discussion started by: robertson1995
5 Replies

6. Shell Programming and Scripting

Help with tail command

Hi All, My query seems to be silly but Iam unable to find where the exact problem lies. I have a script to unzip set of files here is the script #!/bin/ksh Count=`cat /home/gaddamja/Tempfile | wc -l` while do Filename=`cat /home/gaddamja/Tempfile |tail -$Count | head -1` cd... (7 Replies)
Discussion started by: jagadish_gaddam
7 Replies

7. Solaris

Tail command in one line

HI i have to copy the last 5000 lines form a log file and copy the same in the same file .overwriting the same log file. ex: tail -5000 testfile1 > testfile2 cat testfile2 mv tesftfile2 testfile1 will produce the correct result.but i want to have this done in one line???? (4 Replies)
Discussion started by: saurabh84g
4 Replies

8. Shell Programming and Scripting

tail command..

I was wondering how can I do this I have file myfile.txt wc -l is: 5 000 000 I have to remove first 1 000 000 lines from header.. I tryed with tail -4000000 myfile.txt>newfile.txt but it does not work... any help?? (2 Replies)
Discussion started by: amon
2 Replies

9. Shell Programming and Scripting

tail command

Hi , I have found a interesting thing about tail command: when I tried to use 'tail -1 *' to look at every file with the current derectory, I only got one line of result of one file. But if I use 'head -1 *', I would get multiple lines. Is there a way to do get multiple lines with 'tail -1 *'... (3 Replies)
Discussion started by: whatisthis
3 Replies

10. UNIX for Advanced & Expert Users

help with !(tail -2) command.. using pipes

I am trying to using pipe (|) with ! (not) operator to list all the other files except the latest two and I am using the following command. $ ls -ltr *.lst|!(tail -2) ksh: 20050211180252.lst: cannot execute but it is trying to execute the file returned by tail -2. I am able to do that in 4... (8 Replies)
Discussion started by: sdlayeeq
8 Replies
Login or Register to Ask a Question