LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-08-2015, 02:38 AM   #1
azuahaha
LQ Newbie
 
Registered: May 2013
Posts: 20

Rep: Reputation: Disabled
my own rotation ( of log files )


Hello All,

I want to rotate my own log files and Oracle alert.log file, so I wanted to write a script instead of logrotate for different reasons. The problem is, I do not want to lose a single line AND I do not know how to make wait Oracle alert.log file generation. So I'm assuming a log is flowing without stopping and how can I rotate it without losing a single line ?

For testing, I write logger and rotate scripts;

Code:
#!/bin/bash
# logger

logfile=logger.out

for i in {1..10000}
do
        echo "$(date) - $i" >> $logfile
        sleep 0.0001
done
Code:
#!/bin/bash
# rotate

logfile=logger.out

for cnt in {6..1}
do
        cat $logfile.$cnt > $logfile.$((cnt+1))
        echo "$(date) - midnight end point" >> $logfile.$((cnt+1))
done

mv $logfile  $logfile.$cnt
echo "$(date) - midnight start point" > $logfile
echo "$(date) - midnight end point" >> $logfile.$cnt
When I test these scripts, I see one line is missing.
For example, my last test missed "Wed Jul 8 09:34:01 EEST 2015 - 1454" line in both logger.out and logger.out.1

How can i avoid this ?
 
Old 07-08-2015, 02:45 AM   #2
azuahaha
LQ Newbie
 
Registered: May 2013
Posts: 20

Original Poster
Rep: Reputation: Disabled
Well it seems writing here made my brain work better for now.
The problem is within new logfile creation line
Code:
                echo "$(date) - midnight start point" > $logfile
I changed it to use with touch and now it seems it catches all lines succesfully

Code:
#!/bin/bash
# rotate
logfile=logger.out

for cnt in {6..1}
do
        cat $logfile.$cnt > $logfile.$((cnt+1))
        echo "$(date) - midnight end point" >> $logfile.$((cnt+1))
done

mv $logfile  $logfile.$cnt
touch $logfile
echo "$(date) - midnight end point" >> $logfile.$cnt
The only missing part is my header line "midnight start point" and if I add it after touch command, it appears in the second or third line obviously.
So I'll just use it without the header line.

Still, please review my script and if you have a nicer touch, please let me know.

Thanks LinuxQuestions.org
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Default rotation of logins log (/var/log/wmtp) gacanepa Linux - Newbie 2 10-01-2013 07:59 PM
[SOLVED] Log rotation of log files in different directories mahi_nix Linux - Server 7 02-19-2013 06:33 AM
Syslog-ng messages.log log rotation Iyyappan Linux - Server 3 09-16-2012 12:10 PM
How to change Debian log rotation of syslog and daemon.log onmountain Linux - Newbie 2 07-31-2008 03:27 AM
Log Rotation for snort log does not seem to be working CentOS4.5 JasonKretzer Linux - Security 3 06-25-2007 01:25 PM


All times are GMT -5. The time now is 06:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration