[SunHELP] Script to Rename Log Files
Bashar
sunhelp at sunhelp.org
Tue May 15 14:05:41 CDT 2001
Small correction to your great script he do not want to print out the
filenames instead he want to `mv` the old files to the new files here is
the small correction from print at the end to mv
# ----------- SCRIPT START ---------
#!/usr/bin/ksh
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`
# the small correction here from print to mv #
mv $file1 "$filename1$filename2.$month1$day1.y$year1.t${file2[1]}${file2[2]}${file2[3]}"
done
# --------- END SCRIPT --------
KuwaitNet Communications Inc.
Bashar A AlAbdulhadi Sales Manager/Administrator
bashar at kuwaitnet.net http://www.KuwaitNet.net
Phone: (KW) +965-2647060 Fax: (KW) +965-5337060
Phone: (US) +514-2417955 Fax: (US) +208-2755778
ICQ UIN: 19907999 Pager: (KW) 9312471
IRC: Big @ #Kuwaitnet YaHoO ID: kuwaitnets
Toll free (from USA & Canada only) 1-888-KuwaitNET
"Quality, Stability, 24 Hours Tech. Support"
"Think KuwaitNet"
On Tue, 15 May 2001, Lund, Dennis wrote:
> 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>
>
More information about the SunHELP
mailing list