Tags

Related Posts

Share This

Perl par la pratique

Petit tutorial PERL

COURS PERL :
http://www.med.univ-rennes1.fr/~poulique/cours/perl/

—————————————–

#!/usr/bin/perl
#  af – about files

print "Please enter file name " if (-t STDIN);
chop ($­­­­­­name = <STDIN>);

@fdata = stat($­­­­­­name);
@text = ("device","inode","mode","links",
 "user id",
 "group id","device id","size", "accessed",
 "modified","changed","blocksize",
 "block count");

foreach $­­­­­­k(0..$­­­­­­#text) {
 printf "%-12s",$­­­­­­text[$­­­­­­k];
 print $­­­­­­fdata[$­­­­­­k],"n";
 }

———————————————-
#!/usr/bin/perl
use Archive::Tar;
use Net::FTP;

$­­­­­­date=time();
my $­­­­­­ftp_html =
Net::FTP->new('server',Passive=>1,Timeout=>30000),"n";
$­­­­­­ftp_html->login('login','passwd');

$­­­­­­ftp_html->cwd('/'),"n";

        my @fileList2 = $­­­­­­ftp_html->ls('*.gz');
        foreach my $­­­­­­file2 (@fileList2) {
        $­­­­­­ftp_html->delete($­­­­­­file2)
        }

$­­­­­­ftp_html->cwd('/CPNgroupe'),"n";
my @fileList = $­­­­­­ftp_html->ls('*.bak');
foreach my $­­­­­­file (@fileList) {
        $­­­­­­mois="2678400";
        $­­­­­­datef=$­­­­­­ftp_html->mdtm($­­­­­­file),"n";
        $­­­­­­sous= $­­­­­­date – $­­­­­­datef;
            if ( $­­­­­­sous > $­­­­­­mois ) {
                $­­­­­­ftp_html->delete($­­­­­­file);
            }
}

$­­­­­­ftp_html->quit;
——————————————-
$­­­­­­rep= "/test" ;
opendir R, $­­­­­­rep or die "impossible d'ouvrir le rép. $­­­­­­rep";
@liste=readdir(R);
foreach $­­­­­­f (@liste) {
  next if $­­­­­­f eq "." or $­­­­­­f eq "..";
  $­­­­­­file= "$­­­­­­rep/$­­­­­­f";
  if (-f $­­­­­­file) {
   (undef,undef,undef,undef,undef,undef,undef,$­­­­­­size,undef,$­­­­­­mtime)=
stat($­­­­­­file);
  print "$­­­­­­file $­­­­­­mtime $­­­­­­sizen";
  $­­­­­­date=time();
  $­­­­­­sous= $­­­­­­date – $­­­­­­mtime;
  print "$­­­­­­sous";
  $­­­­­­huit= "850";
  if ( $­­­­­­sous > $­­­­­­huit ) {
         print "OUAISSSS";
     }
   }
}
closedir R;
——————————————-
use Archive::Tar;
use File::DosGlob 'glob';
use Net::FTP;

#my @fileList = $­­­­­ftp_html->ls('/info/*.gz');i
#$­­­­­ftp_html = Net::FTP->new('server',Passive=>1);
#$­­­­­ftp_html->login(logint',passwordc');
#$­­­­­ftp_html->binary();
#$­­­­­ftp_html->get("d:/datap/*.gz","1.gz");
#$­­­­­ftp_html->quit;

# $­­­­­ftp_html->get($­­­­­file,fp/$­­­­­file");
# $­­­­­ftp_html->get($­­­­­file,"/datuipe/$­­­­­file");
#    $­­­­­ftp_html->delete($­­­­­file);

#       my @fileList = $­­­­­ftp_html->ls('*.*');
#       foreach my $­­­­­file (@fileList) {
#     $­­­­­test = $­­­­­ftp_html->mdtm($­­­­­file);
#    print "$­­­­­file";
#       }

my $­­­­­ftp_html = Net::FTP->new('server',Passive=>1);
       $­­­­­ftp_html->login('login','password');
       $­­­­­ftp_html->binary();
       $­­­­­ftp_html->cwd('/ls'),"n";
       $­­­­­ftp_html->ls('*.*'),"n";
       print $­­­­­ftp_html->ls('*.*'),"n";
$­­­­­ftp_html->quit;
—————————————–
cd /data/
rm -fr *

ncftp -u COMPTE -p 'PASSWORD' SERVER << TEST
bin
#set confirm-close no
cd test/
get *.*
rm *.*
quit
TEST
—————————————–