FTP search ,grep using perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP search ,grep using perl
# 29  
Old 04-25-2013
I tried that way . Script takes a very long time and doesnt reply back anything
# 30  
Old 04-25-2013
Show your code please.
# 31  
Old 04-25-2013
Code

Code:
#!/usr/bin/perl -w

use Net::FTP;

my @str=("edfiles.txt");
open(OUT,"output.log");

while($line=<STDIN>)
{
        chomp($line); # Remove newline from end of string
        push(@str, $line); # Add string to end of @str array
}

$ftp = Net::FTP->new("ftp.ncdc.noaa.gov");
$ftp->login('anonymous', 'ara2wj@bp.com');
$ftp->cwd("/pub/data/gsod/2012");
$ftp->binary;
#$flag=$ftp->mdtm($_);

my @filenames=$ftp->ls();
print " Total files:", $#filenames + 1, "\n";
$match=0;
foreach (@filenames)
{
        for my $s(@str)
        {
                if(index($_, $s) >= 0)
                {
                         print OUT "$_", " ",  $ftp->size($_),
#                        print $_, " Size:[", $ftp->size($_), "]",
#                                " Mtime ", scalar(localtime($ftp->mdtm($_))),
                                "\n";
                        $match++;
                }
        }
}

if($match == 0) { print "No files matched\n"; }

$ftp->quit();

# 32  
Old 04-25-2013
Are you looking for "edfiles.txt", or do you want to load from edfiles.txt?
# 33  
Old 04-25-2013
Load from Edfiles.txt . It has the list of files i am searching
# 34  
Old 04-25-2013
It's waiting forever because it's still trying to load from stdin, you didn't delete that part.

That code would not load from that file, since that's not what you asked for before.

You copied the code imperfectly, as well, leaving an > out of my instructions.

You also forgot to add the OUT to all the print statements.



Code:
open(IN, "<edfiles.txt");
open(OUT, ">output.log");

while($line=<IN>)
{
        chomp($line); # Remove newline from end of string
        push(@str, $line); # Add string to end of @str array
}

# 35  
Old 04-26-2013
Thank you Again . it worked

I am Relatively very new to Perl scripting . I dont have help at work .
This forum and you are a great help to me .

---------- Post updated 04-26-13 at 01:31 PM ---------- Previous update was 04-25-13 at 04:07 PM ----------

Need help again . Below are the 2 things i need to this script

1. This script creates an output to output.log . when i run again it should create a backup file example
Code:
output.log.<date>

with timestamp
2. Check the difference of the old file and the new file and report it if there is an update .

I have added the below script , the second script is an example of creating a backup file with timestamp but i dont know how to club that script to the 1st script



Code:
#!/usr/bin/perl -w

use Net::FTP;


my @str=("files.txt");

open(IN, "<files.txt");
open(OUT, ">output.log");

while($line=<IN>)
{
        chomp($line); # Remove newline from end of string
        push(@str, $line); # Add string to end of @str array
}

$ftp = Net::FTP->new("hostname");
$ftp->login('user', 'password');
$ftp->cwd("path");
$ftp->binary;

my @filenames=$ftp->ls();
print " Total files:", $#filenames + 1, "\n";
$match=0;
foreach (@filenames)
{
        for my $s(@str)
        {
                if(index($_, $s) >= 0)
                {
                         print OUT "$_", " ",  $ftp->size($_),
#                        print $_, " Size:[", $ftp->size($_), "]",
#                                " Mtime ", scalar(localtime($ftp->mdtm($_))),
                                "\n";
                        $match++;
                        copy ("output.log", "output.log".$date."");
                }
        }
}

if($match == 0) { print "No files matched\n"; }

$ftp->quit();


Code:
use File::Copy;
my (undef,undef,undef,$mday,$mon,$year,undef,undef,undef) = localtime;
$year += 1900;
$mon += 1;
$date = sprintf "%02d/%02d/%04d", $mon, $mday, $year;
#copy (" output.log","output.log".$date."");

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

3. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

4. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

5. HP-UX

[Solved] Unable to rename file in ftp server .Net:FTP perl

Hello All, I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir. rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed. Can some body help me to... (2 Replies)
Discussion started by: krsnadasa
2 Replies

6. UNIX for Dummies Questions & Answers

recursive search and ftp

Could someone help me in recursive search and ftp'ing the files to remote server? The host machine will have /dir1/dira/list_of_files1 /dir1/dirb/list_of_files2 /dir1/dirc/list_of_files3 . . . so., I need to search from dir1 recursively (only one level down) and find all the files that... (1 Reply)
Discussion started by: brahmi
1 Replies

7. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

8. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

9. Shell Programming and Scripting

using finddepth in ftp to search for directories in perl

Hi all, I have script which downloads the build and copies onto the local machine I am able to download files in a directory, but unable to get the files in subdierctories. I am using finddepth to search for sub directories but I am unable to do so. Here is my code: ... (0 Replies)
Discussion started by: gurukottur
0 Replies
Login or Register to Ask a Question