- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Need help with -exec option of "find" command.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2007 04:24 PM
тАО01-11-2007 04:24 PM
Need help with -exec option of "find" command.
Iam new to this .
My task is to code a script which will rename log files with "date" appended to it.
FOr example :-
pkg_name.cntl.log has to be renamed to
pgk_name.cntl.log.yymmdd.hh.mm
ex. WM01P.cntl.log.060108.13.05
I have to usethe find command with -exec option.
I ran the find command to check it out [with -exec option].
find /etc/cmcluster -name *cntl.log -type f -exec ls -ltr {} \;
and output is :-
/etc/cmcluster/C01/dbC01.cntl.log
/etc/cmcluster/C01/ciC01.cntl.log
/etc/cmcluster/DS1/dbDS1.cntl.log
/etc/cmcluster/DS1/ciDS1.cntl.log
/etc/cmcluster/DS2/dbDS2.cntl.log
/etc/cmcluster/DS2/ciDS2.cntl.log
/etc/cmcluster/DS3/dbDS3.cntl.log
/etc/cmcluster/DS3/ciDS3.cntl.log
/etc/cmcluster/E01/dbE01.cntl.log
/etc/cmcluster/E01/ciE01.cntl.log
/etc/cmcluster/S01/dbS01.cntl.log
/etc/cmcluster/S01/ciS01.cntl.log
/etc/cmcluster/U02/dbU02.cntl.log
/etc/cmcluster/U02/ciU02.cntl.log
/etc/cmcluster/oracledevl/oracledevl.cntl.log
/etc/cmcluster/DW1/dbDW1.cntl.log
/etc/cmcluster/DW1/ciDW1.cntl.log
Please note that the directories are different after cmluster direcotry.
Let me know how to script this.
Thanks in Advance
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2007 05:02 PM
тАО01-11-2007 05:02 PM
Re: Need help with -exec option of "find" command.
In a pinch you make the fixed 'glob' string an argument.
I would choose this solution because it will work unmodified on Hpux, Tru64, Linux, Windoze, OpenVMS,... independent of a shell choice and so on.
hth,
Hein.
use strict;
use warnings;
my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time);
my $timestamp = sprintf (".%02d%02d%02d.%02d.%02d",
$year%100, $mon+1, $mday, $hour, $min);
while (<*.log>) {
rename $_, $_ . $timestamp;
}
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2007 05:09 PM
тАО01-11-2007 05:09 PM
Re: Need help with -exec option of "find" command.
You clearly need to traverse a directory tree. That's nor too hard in perl through a module: File::Find
But I would possibly let find do the finding and change the perl to the sample below(untested, the other was tested)
The -exec perl my-rename.pl {}
Hein.
------------------ my-rename.pl ---------
use strict;
use warnings;
my $old = shift;
my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time);
my $new = sprintf ("%s.%02d%02d%02d.%02d.%02d",
$old, $year%100, $mon+1, $mday, $hour, $min);
rename $old, $new;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2007 05:11 PM
тАО01-11-2007 05:11 PM
Re: Need help with -exec option of "find" command.
---
TAIL=$(date "+%m%d%y.%H.%M.%S")
for file in `find /etc/cmcluster -name '*cntl.log' -type f`
do
mv $file $file.$TAIL
done
---
Note the single quote around wildcard * with the
'find' command line. Modify the date command to
get whatever format you want.
- Biswajit
- Tags:
- date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2007 08:02 PM
тАО01-11-2007 08:02 PM
Re: Need help with -exec option of "find" command.
Thanks all of you.
I used your suggestions adn tried and it works. Will decide on one of these.
Thanks once again !
Sagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2007 11:35 PM
тАО01-11-2007 11:35 PM
Re: Need help with -exec option of "find" command.
Here's another, short variation to accomplish your goal:
# EXT=`date "+%m%d%y.%H.%M"`
# find /etc/cmcluster -type f -name "*cntl.log" | xargs -i mv {} {}.$EXT
Regards!
...JRF...