Rotating log files through shell script
Hello. I am running below command to capture ping response from a server:
ping server1 | perl -nle 'BEGIN {$|++} print scalar(localtime), " ", $_' > ping_response_server1 & Now this generates a log file name ping_response_server1. I want this file to be rotated after reaching certain threshold size. For that i tried to create below shell script: Code:
#!/bin/bash Any idea what is wrong with this concept? |
Why not use logrotate?
|
Quote:
Built for it, actually. |
And not too difficult to use, generally it's already installed and set up, just add the wanted log in /etc/logrotate.conf
Code:
/path/to/logfile.log { |
the old logfile is still opened and in use, the commands removed only the directory entry - and created another one.
|
Ok. I am going to use logrotate. To setup this i've created a file "ping" in /etc/logrotate.d as below:
Code:
/tmp/ping_response_server1 Is that approach correct? |
You could remove the ping file from /etc/cron.hourly, put it on different path
eg: /home/antriksh/etc Then add a crontab entry like Code:
00 * * * * /usr/sbin/logrotate /home/antriksh/etc/ping Yes your approach seems correct, leave the script in /etc/cron.hourly directory |
Thank you everyone for the help. logrotate did the trick.
|
glad to hear that.
(if you really want to say thanks just click on yes) |
All times are GMT -5. The time now is 04:45 AM. |