tail and log rotation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting tail and log rotation
# 1  
Old 11-06-2012
tail and log rotation

Need some suggestion with an old problem form a thread here:
https://www.unix.com/shell-programmin...ement-awk.html

Since my log is large, I did get help to make a line that splits the log into two parts
Code:
tail -f syslog | awk '!/snmpd|ntpd|reject/{print | "tee newlog"}'

(change from daemon.log to syslog)

Problem is that tail seems to stop and does not update the log file.

I then made a script that looked at the "newlog" and if it did not get updated in 3 hour, restarts the tail.
Its not a good solution, since I do loose 3 hour of data.

Recently I did see some post that tail have this problem with log rotate.
When syslog rotates to syslog.1, tail stops getting data, since it does not understand that it need to look at the new file.

I made a new script that restarts the tail if syslog.1 gets updated:
Code:
while [ 1 ]
do
file_now=$(ls -l /var/log/syslog.1 | awk '{print $8}')

if [ "$file_start" != "$file_now" ]; then
        file_start=$(ls -l /var/log/syslog.1 | awk '{print $8}')
        tail -f /var/logsyslog | awk '!/snmpd|ntpd|reject/{print | "tee newlog"}'
        fi

sleep 60
done

Is this a good solution, or you guys having a better solution for this?
# 2  
Old 11-06-2012
If you are on Linux or have GNU coreutils available, you can use

Code:
tail --follow=name filename

When logrotation happens, you will see a message like

Code:
tail: filename: No such file or directory
tail: `filename' has appeared;  following end of new file

You can redirect stderr to /dev/null if you do not want to see this message.
This User Gave Thanks to hergp For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

When redirecting tail -F output fail after log rotation?

Redirecting the tail output fails when log rotation happens even though i have used -F. But when i tail and see the output on terminal this does not happen. Note i have also used & to execute this statement in background. Suppose if i want to tail a file /opt/SAMPLE.txt and redirect its output... (1 Reply)
Discussion started by: CN1
1 Replies

2. OS X (Apple)

Mavericks log rotation

In Mavericks, Apple has apparently moved control of log rotation to ASL. There's a 'ttl' value to determine how long log files will stick around for. I can compress them, change the way they're named, limit them by size, etc. But the one thing I cannot find is how to NOT keep one log file per... (0 Replies)
Discussion started by: jnojr
0 Replies

3. Solaris

Log rotation

Hi All! I seem to have a problem with log rotation, unless I am doing something wrong, I have type the following command for testing purposes to see if the -s option works but he did not: logadm -w /var/adm/messages -C 8 -c -s 512k -t '/var/adm/messages.$n' -z 1 the file is now at this... (7 Replies)
Discussion started by: fretagi
7 Replies

4. UNIX for Dummies Questions & Answers

Log Rotation

Hi Guys, Good morning, I just want to know and collect ideas on this one. Regarding rotation of logs as I've observed it's not consistently functioning. I have a server with 8 Partitions, each partition has a dedicated directory for the logs that is needed and I set it every 5mins (300secs) the... (1 Reply)
Discussion started by: rymnd_12345
1 Replies

5. Solaris

Log rotation, twice

hi folk, need advise regarding the log rotation, i have the logadm set at 30 2 * * * /usr/sbin/logadm so it supposed to rotate once per day, but now it rotated twice! but someone my log will rotate at 2:30 AM, but then another 2 hours later, it creates a new and rotate a new log again,... (2 Replies)
Discussion started by: dehetoxic
2 Replies

6. Solaris

Solaris log rotation

HI, What is log rotation in Solaris ? What are the essential steps to perform log rotation in Solaris? (1 Reply)
Discussion started by: Revathi@1
1 Replies

7. Solaris

Log Rotation of Catalina.out

Hi, Recently i received a request to rotate logs of catalina.out (tomcat). The file size was about 807 MB. I used logadm to truncate the log ( -c ) and zip (-z 0) it. Everything worked fine, catalina.out.0.gz was created (22 MB) and the size of original catalina.out became 0kb. After... (2 Replies)
Discussion started by: Mack1982
2 Replies

8. Shell Programming and Scripting

log rotation and autosys

Hi, I current have many apps servers running and need to create a script to rotate logs daily, and then create an autosys job to delete logs that are older than 30 days. I was thrown into this and have no idea what to do, please help me get started, thanks! -----Post Update----- and i will... (6 Replies)
Discussion started by: new2learn09
6 Replies

9. Shell Programming and Scripting

log rotation

Hello all. Due to some reason I can not use HUP to rotate needed log files. So I use the standard method: cp $file $file.1 cat /dev/null > $file But if Java application in this time writing the output to $file, in the beginning of it appears many "^@^@^@^@^@^@". How to avoid it? Or how... (6 Replies)
Discussion started by: mirusnet
6 Replies

10. HP-UX

Log rotation on HP-UX

Can anyone post a sample log rotate and archive configuration on HP-UX? I really don't know how to do that... :( (3 Replies)
Discussion started by: untamed
3 Replies
Login or Register to Ask a Question