- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Use Perl script to sort the file list by date ...
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
тАО07-23-2009 02:48 AM
тАО07-23-2009 02:48 AM
Use Perl script to sort the file list by date in ftp and delete the old files
I used the Net::Ftp and tried the ftp->ls. But it could not sort the files by date.
Can anyone help ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2009 03:41 AM
тАО07-23-2009 03:41 AM
Re: Use Perl script to sort the file list by date in ftp and delete the old files
Sounds like a project from a perl scripting class.
I like perl but would not use it for this.
find /path_to_apache_logs -name "access_log.*" -mtime 1 -exec rm {} \;
That is an example telling find to delete all apache logs more than a day old and delete them.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2009 03:58 AM
тАО07-23-2009 03:58 AM
Re: Use Perl script to sort the file list by date in ftp and delete the old files
"My project..."
That sounds like homework. That said, if you use 'ftp->ls' method you get filenames. If you use 'ftp->dir' you get the equivalent of a long listing from 'ls'. You still need to write code to sort by date.
I might use 'ftp->ls' to collect the filenames in an hash with the filename as a key while calling 'stat()' on each file and store it's 'mtime' as the hash data. From there, you can do as you please.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2009 05:03 AM
тАО07-23-2009 05:03 AM
Re: Use Perl script to sort the file list by date in ftp and delete the old files
Oops, I keep forgetting that you want to use 'ftp' to collect your file list. In that case, use the 'ftp->dir' method to return long listing of files (together with their date information). Since you can't stat() in this case, parse-out the date fields and convert them to epoch seconds for sorting and comparison purposes. Once you have reduced your list to the files you want to delete, run another FTP session to issue your removal.
I offer all this in the abstract assuming that you "must" use FTP to encapsulate your objective.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-27-2009 07:22 PM
тАО07-27-2009 07:22 PM
Re: Use Perl script to sort the file list by date in ftp and delete the old files
Following is my code:
my $ftp = Net::FTP->new("$ftp_server",Timeout => 9000,Debug => 1);
$ftp->login("$ftp_login_name","$ftp_password") or die "$_: cannot login:".$ftp->message;
$ftp->cwd("$path");
my @fileListArray = $ftp->dir("LISTING*");
chomp(@fileListArray);
my $fileCount = @fileListArray;
if($fileCount > 0) {
while($i < $fileCount-$amountToKeep) {
my @tmp_x = split /\s+/,$fileListArray[$i];
my $current_file = $tmp_x[$#tmp_x];
system("del $path\\$fileListArray[$i]");
$i++;
}
}
$ftp->quit;
And is now trying to work the part for sorting the files by the dates.