LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-12-2009, 05:36 PM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
Logrotate/ bash script not rotating file


I'm collecting sflow data from a switch to a file. At 2300 every night I want
to roll-over the file to file.1 and start with a new file. But it looks like
the log rotation is not happening : at 2200 my sflow data collection stops.

Following is the way I'm doing it.

collect.sh shell script calls a C program to collect the sflow data,
filter the output and send the filtered data to /tmp/sflow.log file. I run
this script from the CLI as root:

collect.sh script:

Code:
EXE="/bin/sflowtool/sflowtool"
EGREP="/bin/egrep"
FILTER="dstIP|srcIP|IPProtocol|rcPort|stPort"

FILE="/tmp/sflow.log"


$EXE | $EGREP "$FILTER" > $FILE 2>&1 &
rotate.sh kills any "sflow" process (or PID) and is supposed to rotate the
/tmp/sflow.log log to /tmp/sflow.log.1 and
start the collect.sh shell script again & starts collecting log to /tmp/sflow.log. I run
this script from root's crontab as:

Quote:
0 23 * * * /bin/rotate.sh > "/var/log/lorgorate.`/bin/date +\%a`.log" 2>&1
rotate.sh script:

Code:
EXE="/bin/sflow_collect.sh"
PKILL="/usr/bin/pkill"

LOGROTATE="/usr/sbin/logrotate"

LOGROTATE_FILE="sflow_logrotate"

$PKILL -9 sflow

$LOGROTATE -f $LOGROTATE_FILE

$EXE
sflow_logrotate file:

Code:
/tmp/sflow.log {
        rotate 30
        nocompress
        create
}
Thanks for any help.

Last edited by noir911; 01-12-2009 at 05:37 PM.
 
Old 01-14-2009, 02:06 AM   #2
h725
Member
 
Registered: Apr 2008
Posts: 114

Rep: Reputation: 15
Quote:
Originally Posted by noir911 View Post
I'm collecting sflow data from a switch to a file. At 2300 every night I want
to roll-over the file to file.1 and start with a new file. But it looks like
the log rotation is not happening : at 2200 my sflow data collection stops.

Following is the way I'm doing it.

collect.sh shell script calls a C program to collect the sflow data,
filter the output and send the filtered data to /tmp/sflow.log file. I run
this script from the CLI as root:

collect.sh script:

Code:
EXE="/bin/sflowtool/sflowtool"
EGREP="/bin/egrep"
FILTER="dstIP|srcIP|IPProtocol|rcPort|stPort"

FILE="/tmp/sflow.log"


$EXE | $EGREP "$FILTER" > $FILE 2>&1 &
rotate.sh kills any "sflow" process (or PID) and is supposed to rotate the
/tmp/sflow.log log to /tmp/sflow.log.1 and
start the collect.sh shell script again & starts collecting log to /tmp/sflow.log. I run
this script from root's crontab as:



rotate.sh script:

Code:
EXE="/bin/sflow_collect.sh"
PKILL="/usr/bin/pkill"

LOGROTATE="/usr/sbin/logrotate"

LOGROTATE_FILE="sflow_logrotate"

$PKILL -9 sflow

$LOGROTATE -f $LOGROTATE_FILE

$EXE
sflow_logrotate file:

Code:
/tmp/sflow.log {
        rotate 30
        nocompress
        create
}
Thanks for any help.
Hi,
just a little idea: maybe in "rotate.sh" you need to specify the absolute path of "slow_logrotate" file?
What happened if you try: logrotate -d /path/to/sflow_logrotate ?
 
Old 01-15-2009, 03:56 PM   #3
noir911
Member
 
Registered: Apr 2004
Posts: 682

Original Poster
Rep: Reputation: Disabled
Solved: it was the rotate.sh script which ended after the kill -9 command because it was killing itself. Replaced $PKILL -9 sflow with $PKILL -9 sflowtool - solved the problem.
 
  


Reply



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
rotating apache logs.....looking for a good script to delete old log file ringding Linux - Server 6 04-25-2020 12:59 PM
Bash script for listing FTP usage as the file name of a file created in each share jojothedogboy Programming 1 12-05-2008 03:35 PM
How to take value from file (bash script) teguh.purnama Linux - Newbie 3 09-08-2008 07:32 AM
logrotate shell script help with existing script sridhar11 Debian 7 11-04-2005 04:11 AM
adding a rotating - to my bash script Cinematography Programming 3 08-31-2005 01:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:42 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
Open Source Consulting | Domain Registration