LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Logrotate/ bash script not rotating file (https://www.linuxquestions.org/questions/linux-server-73/logrotate-bash-script-not-rotating-file-696845/)

noir911 01-12-2009 05:36 PM

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.

h725 01-14-2009 02:06 AM

Quote:

Originally Posted by noir911 (Post 3406331)
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 ?

noir911 01-15-2009 03:56 PM

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.


All times are GMT -5. The time now is 09:32 PM.