[linux-support] log file truncate

milosh support at plexus.shacknet.nu
Mon Jan 17 20:33:38 CET 2005


--- Christof.Lauber at swissinfo.ch wrote:
> hallo zusammen
> ich suche eine schöne möglichkeit ein logfile abzuschneiden, während ein
> prozess noch rein schreibt.
das klingt wie ein job für ed ;) hab n kleines script gemacht, welches ins
file reingeht und soviele zeilen uebrig laesst wie du willst. $1 ist der
filename, $2 die anzahl zeilen. funzt ohne tmp datei und den schreibenden
prozess _sollte_ es net stoeren. copy&paste:

#!/bin/bash
lines=`wc -l $1 |tr -s ' ' |cut -d' ' -f2`
let tresh=$lines-$2

ed <<! $1
1,${tresh}d
w
q
!

hab spass
miLosh


More information about the Linux-support mailing list