[SunHELP] Script to Rename Log Files

Lund, Dennis sunhelp at sunhelp.org
Tue May 15 13:17:20 CDT 2001


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C0DD6B.47C36200
Content-Type: text/plain

First I would try to find what/where/how the files are being created and try
to change
it there.  If that can not be done then you could use this script:

#/bin/ksh
#
# Script to rename file FROM:
# acct.log.14May2001_09_10_12
#             TO:
# acctlog.may14.y2001.t091012

for file1 in `ls /export/home/lundd/test/tstdir`
do

filename1=`print $file1 | awk -F. '{print $1}'`
filename2=`print $file1 | awk -F. '{print $2}'`
filename3=`print $file1 | awk -F. '{print $3}'`

set -A file2 `print $filename3 | awk -F_ '{print $1, $2, $3, $4}'`

day1=`print "${file2[0]}" | cut -c1,2`
month1=`print "${file2[0]}" | cut -c3,4,5 | tr [A-Z] [a-z]`
year1=`print "${file2[0]}" | cut -c6,7,8,9`

print
"$filename1$filename2.$month1$day1.y$year1.t${file2[1]}${file2[2]}${file2[
3]}"

done

I know its kind of goofy, but it works.  If you file names are not
consistent, this
will not work.  Specifically the "cut" command for "month1" would be a
concern if the
month is June, August or something other than a three character
abbreviation.

Dennis L. Lund

-----Original Message-----
From: ymui at royalsunalliance.ca [mailto:ymui at royalsunalliance.ca]
Sent: Tuesday, May 15, 2001 9:50 AM
To: sunhelp at sunhelp.org
Subject: [SunHELP] Script to Rename Log Files


Dear Managers,

Does anyone know how to write a script to rename a bunch of log files
dynamically generated with timestamps ?

For example, log files are generated with a pattern like
'acct.log.14May2001_09_10_12'.  I would like to rename all these as
'acctlog.may14.y2001.t091012'.

Your help is much appreciated !

Thanks, Yingha Mui.

_______________________________________________
SunHELP maillist  -  SunHELP at sunhelp.org
http://www.sunhelp.org/mailman/listinfo/sunhelp


<html>
<body>
<font size="2" face="Arial"><span style="mso-fareast-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">
- - - - - - - Appended by Scientific-Atlanta, Inc. - - - - - - -
<span style="font-size:10.0pt;font-family:Arial;
mso-fareast-font-family:"Arial";mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA"></span><font face="Arial" size="2"><span style="mso-fareast-font-family: Arial; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">This e-mail and any attachments may contain information which is confidential, proprietary, privileged or otherwise protected by law. The information is solely intended for the named addressee (or a person responsible for delivering it to the addressee). If you are not the intended recipient of this message, you are not authorized to read, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer.</span></font></p>
</body>
</html>

------_=_NextPart_001_01C0DD6B.47C36200
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; charset=3Dus-ascii">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version 5.5.2653.12">
<TITLE>RE: [SunHELP] Script to Rename Log Files</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>First I would try to find what/where/how the files are be=
ing created and try to change</FONT>
<BR><FONT SIZE=3D2>it there.  If that can not be done then you could u=
se this script:</FONT>
</P>

<P><FONT SIZE=3D2>#/bin/ksh</FONT>
<BR><FONT SIZE=3D2>#</FONT>
<BR><FONT SIZE=3D2># Script to rename file FROM:</FONT>
<BR><FONT SIZE=3D2># acct.log.14May2001_09_10_12</FONT>
<BR><FONT SIZE=3D2>#         &=
nbsp;   TO:</FONT>
<BR><FONT SIZE=3D2># acctlog.may14.y2001.t091012</FONT>
</P>

<P><FONT SIZE=3D2>for file1 in `ls /export/home/lundd/test/tstdir`</FONT>
<BR><FONT SIZE=3D2>do</FONT>
</P>

<P><FONT SIZE=3D2>filename1=3D`print $file1 | awk -F. '{print $1}'`</FONT>
<BR><FONT SIZE=3D2>filename2=3D`print $file1 | awk -F. '{print $2}'`</FONT>
<BR><FONT SIZE=3D2>filename3=3D`print $file1 | awk -F. '{print $3}'`</FONT>
</P>

<P><FONT SIZE=3D2>set -A file2 `print $filename3 | awk -F_ '{print $1, $2, =
$3, $4}'`</FONT>
</P>

<P><FONT SIZE=3D2>day1=3D`print "${file2[0]}" | cut -c1,2`</FONT>
<BR><FONT SIZE=3D2>month1=3D`print "${file2[0]}" | cut -c3,4,5 | =
tr [A-Z] [a-z]`</FONT>
<BR><FONT SIZE=3D2>year1=3D`print "${file2[0]}" | cut -c6,7,8,9`<=
/FONT>
</P>

<P><FONT SIZE=3D2>print "$filename1$filename2.$month1$day1.y$year1.t${=
file2[1]}${file2[2]}${file2[</FONT>
<BR><FONT SIZE=3D2>3]}"</FONT>
</P>

<P><FONT SIZE=3D2>done</FONT>
</P>

<P><FONT SIZE=3D2>I know its kind of goofy, but it works.  If you file=
 names are not consistent, this</FONT>
<BR><FONT SIZE=3D2>will not work.  Specifically the "cut" co=
mmand for "month1" would be a concern if the</FONT>
<BR><FONT SIZE=3D2>month is June, August or something other than a three ch=
aracter abbreviation.</FONT>
</P>

<P><FONT SIZE=3D2>Dennis L. Lund</FONT>
</P>

<P><FONT SIZE=3D2>-----Original Message-----</FONT>
<BR><FONT SIZE=3D2>From: ymui at royalsunalliance.ca [<A HREF=3D"mailto:ymui at r=
oyalsunalliance.ca">mailto:ymui at royalsunalliance.ca</A>]</FONT>
<BR><FONT SIZE=3D2>Sent: Tuesday, May 15, 2001 9:50 AM</FONT>
<BR><FONT SIZE=3D2>To: sunhelp at sunhelp.org</FONT>
<BR><FONT SIZE=3D2>Subject: [SunHELP] Script to Rename Log Files</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>Dear Managers,</FONT>
</P>

<P><FONT SIZE=3D2>Does anyone know how to write a script to rename a bunch =
of log files</FONT>
<BR><FONT SIZE=3D2>dynamically generated with timestamps ?</FONT>
</P>

<P><FONT SIZE=3D2>For example, log files are generated with a pattern like<=
/FONT>
<BR><FONT SIZE=3D2>'acct.log.14May2001_09_10_12'.  I would like to ren=
ame all these as</FONT>
<BR><FONT SIZE=3D2>'acctlog.may14.y2001.t091012'.</FONT>
</P>

<P><FONT SIZE=3D2>Your help is much appreciated !</FONT>
</P>

<P><FONT SIZE=3D2>Thanks, Yingha Mui.</FONT>
</P>

<P><FONT SIZE=3D2>_______________________________________________</FONT>
<BR><FONT SIZE=3D2>SunHELP maillist  -  SunHELP at sunhelp.org</FONT>
<BR><FONT SIZE=3D2><A HREF=3D"http://www.sunhelp.org/mailman/listinfo/sunhe=
lp" TARGET=3D"_blank">http://www.sunhelp.org/mailman/listinfo/sunhelp</A></=
FONT>
</P>

<CODE><FONT SIZE=3D3><BR>
<BR>
<html><BR>
<body><BR>
<font size=3D"2" face=3D"Arial"><span style=3D"mso-fareast-font-family: Tim=
es New Roman; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bi=
di-language: AR-SA"><BR>
- - - - - - - Appended by Scientific-Atlanta, Inc. - - - - - - -<BR>
<span style=3D"font-size:10.0pt;font-family:Arial;<BR>
mso-fareast-font-family:"Arial";mso-ansi-language:EN-US;mso-farea=
st-language:<BR>
EN-US;mso-bidi-language:AR-SA"></span><font face=3D"Arial" size=3D"2"><span=
 style=3D"mso-fareast-font-family: Arial; mso-ansi-language: EN-US; mso-far=
east-language: EN-US; mso-bidi-language: AR-SA">This e-mail and any attachm=
ents may contain information which is confidential, proprietary, privileged=
 or otherwise protected by law. The information is solely intended for the =
named addressee (or a person responsible for delivering it to the addressee=
). If you are not the intended recipient of this message, you are not autho=
rized to read, print, retain, copy or disseminate this message or any part =
of it. If you have received this e-mail in error, please notify the sender =
immediately by return e-mail and delete it from your computer.</span></font=
></p><BR>
</body><BR>
</html><BR>
</FONT></CODE></BODY>
</HTML>
------_=_NextPart_001_01C0DD6B.47C36200--



More information about the SunHELP mailing list