Monday 15 February 2010

shell - Log file rollover -


I have a custom script running, I want to redirect some execution steps of the script to a log file.

I need to - When the log file exceeds 20 MB size, I will move the contents to a new file and my script reconfigures the logfile. At any time, I will have a backup of the log material recently. I tried to come up with the logic below:

  if the [-e "$ logfile"] log-in = ls -l $ logfile | Awk '{print $ 5}' ls -l $ logfile | Awk '{print $ 5}' if ["$ logsize" -gt 2097152] then MV $ logfile $ (date + "% Y% m% d% H% M"). Log in $ logfilefi $ logfile fi   

I would like to get the views of the experts and tell me if there is any other efficient way to do this.

I think you should use logrootate Command should be used.

Read one on this

A sample configuration for your needs will be like this:

  / var / log / logfile {missingok size 20m Rotate 5   

}

No comments:

Post a Comment