Numbering

I'm trying to do a script that will look for a log file if it is already there change the name to another name.

I.E

if log.0 is there
rename to log.1
rename log.1 to log.2
rename log.2 to log.3 and so on.

Only thing is I got no idea where or what is the best command to use for this? I'm was thinking maybe mixing in sed and awk some how and doing it that way. As I said though I got no idea.

Perfect example the log files on /var/adm/log you got log.0 log.1 log.2 and so on these files have records and everytime a new log is needed the old log.X number moves up to the next number. Either it be 1 thru to 400.

If anyone can shed some light on this for me thanks a heap.

:slight_smile:

What OS are you using?

If Solaris - look at /usr/lib/newsyslog - it's a script that does exactly what you are asking for. I can't post it since it is copyright.

I don't know if other OSes have this or something like it.

Hi,
I have something 4 u.
for e.g. lets say you want to create a file log.n. so u need to check if it already exists. what you can do is

for i in `ls log*|cut -d"." -f2|sort -n`
do
if [ $n -lt $i ]
then
echo "file exists"
else
echo "creating new log file"
# add you file creation code here
# may b it will something like this
prog 1>log.$n 2>&1
fi
done

hope this helps
rgds
penguin

Just make sure you move backwards from the hightst number to the lowest. If you change 1 to 2 before changing 2 to 3 all three files will have the same data.