no way to compare when less than two revisions
Différences
Ci-dessous, les différences entre deux révisions de la page.
— | informatique:langages:scripts_perl [2016/10/10 15:41] (Version actuelle) – créée - modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ==== Tester un port en TCP ou UDP ==== | ||
+ | <code perl> | ||
+ | #!/bin/perl | ||
+ | use Net::Ping; | ||
+ | my ($host, | ||
+ | my $timeout=5; | ||
+ | $p = Net:: | ||
+ | $p-> | ||
+ | $ret=$p-> | ||
+ | # 0=ok, 1=non joignable | ||
+ | undef($p); | ||
+ | exit($ret==0); | ||
+ | </ | ||
+ | ou | ||
+ | |||
+ | <code perl> | ||
+ | # | ||
+ | use strict; | ||
+ | use Socket; | ||
+ | use File:: | ||
+ | |||
+ | my ($remote, | ||
+ | my $fic = (" | ||
+ | open(FIC,"< | ||
+ | while(< | ||
+ | { | ||
+ | $ligne =" | ||
+ | chomp($ligne); | ||
+ | @server = split(/;/, | ||
+ | $remote = $server[0]; | ||
+ | $port = $server[1]; | ||
+ | if ($port =~ /\D/) { $port = getservbyname($port, | ||
+ | die "No port" unless $port; | ||
+ | $iaddr | ||
+ | $paddr | ||
+ | $proto | ||
+ | socket(SOCK, | ||
+ | print " | ||
+ | connect(SOCK, | ||
+ | print " | ||
+ | close (SOCK) | ||
+ | } | ||
+ | close(FIC); | ||
+ | print " | ||
+ | </ | ||
+ | |||
+ | On créé un fichier // | ||
+ | |||
+ | server;port | ||
+ | |||
+ | :!: Aucun soucis en TCP, par contre en UDP ça peut ne pas fonctionner (dépend du serveur et du service en face). | ||
+ | |||
+ | |||
+ | ==== Vérifier si un fichier a été modifié depuis n secondes ==== | ||
+ | <code perl> | ||
+ | use File:: | ||
+ | use File:: | ||
+ | $FILE_FAX=" | ||
+ | $FILE_RTG=" | ||
+ | $FILE_LOG=" | ||
+ | @temps = localtime(time); | ||
+ | $jour = sprintf(" | ||
+ | $mois = sprintf(" | ||
+ | $annee = sprintf(" | ||
+ | $heure = sprintf(" | ||
+ | $min = sprintf(" | ||
+ | | ||
+ | sub test_fax() | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | if ($delay_fax > 600) { | ||
+ | print FICLOG " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | open(FICLOG,">> | ||
+ | if (-e $FILE_FAX) { test_fax } else { print FICLOG " | ||
+ | if (-e $FILE_RTG) { test_rtg } else { print FICLOG " | ||
+ | close(FICLOG); | ||
+ | </ | ||
+ | |||
+ | == vxtree.pl == | ||
+ | |||
+ | < | ||
+ | # | ||
+ | # | ||
+ | # vxtree.pl | ||
+ | # best viewed in wide xterm | ||
+ | # | ||
+ | # Aug 2003 - Richard Quixley JPMorgan | ||
+ | # | ||
+ | # | ||
+ | # Identifies the following volume types: | ||
+ | # | ||
+ | # 1. concat | ||
+ | # 2. stripe | ||
+ | # 3. mirror | ||
+ | # 4. raid = (raid-5) | ||
+ | # 5. mirrored-stripe | ||
+ | # 6. [layered volume] - striped-mirror (" | ||
+ | # 7. [layered volume] - concat-mirror (" | ||
+ | |||
+ | |||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | |||
+ | |||
+ | use Getopt:: | ||
+ | |||
+ | sub check_vxvm { | ||
+ | ( `swlist VRTSvxvm` ) || die " | ||
+ | } | ||
+ | |||
+ | |||
+ | sub get_dg { | ||
+ | @dg_list=(); | ||
+ | @dg_list=`/ | ||
+ | my $n=0; | ||
+ | foreach $item (@dg_list) { | ||
+ | my @f = split(" | ||
+ | $dg_list[$n] = $f[1]; | ||
+ | ++$n; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | sub check_root { | ||
+ | my $id=`/ | ||
+ | if ( $id > 0 ) { | ||
+ | print " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | # do disks | ||
+ | sub get_disks { | ||
+ | & | ||
+ | my $arg; | ||
+ | $arg=scalar (@ARGV); | ||
+ | if ( $arg < 1 ) { | ||
+ | & | ||
+ | } else { | ||
+ | @dg_list=@ARGV; | ||
+ | } | ||
+ | |||
+ | |||
+ | foreach $dg (@dg_list) { | ||
+ | $gp_size=0; | ||
+ | $gp_free=0; | ||
+ | my @gp_size=`/ | ||
+ | foreach my $line (@gp_size) { | ||
+ | my @arg=split(" | ||
+ | $gp_size += $arg[5] / 2048000; | ||
+ | } | ||
+ | my @gp_free=`/ | ||
+ | foreach my $line (@gp_free) { | ||
+ | my @arg=split(" | ||
+ | $gp_free += $arg[4] / 2048000; | ||
+ | } | ||
+ | printf "\nDG %-10s ------------------------------------------------------------------ total/free %.2f/%.2f Gb\n", $dg, $gp_size, $gp_free; | ||
+ | @dg_disks=(); | ||
+ | @dg_disks=`/ | ||
+ | foreach $line (@dg_disks) { | ||
+ | my @f = split(" | ||
+ | $dg_disk = $f[1]; | ||
+ | $dg_devices = $f[2]; | ||
+ | $disk_size = $f[5]/ | ||
+ | $gp_disk_free=0; | ||
+ | my @gp_disk_free=`/ | ||
+ | foreach my $line (@gp_disk_free) { | ||
+ | my @arg=split(" | ||
+ | $gp_disk_free += $arg[4] / 2048000; | ||
+ | } | ||
+ | printf " | ||
+ | #if ( ! $Options{s} ) { | ||
+ | @sdisk=(); | ||
+ | @sdisk=`/ | ||
+ | unless ( $Options{s} ) { | ||
+ | | ||
+ | my @f = split(" | ||
+ | $sd_name = $f[1]; | ||
+ | $sd_size = $f[5]/ | ||
+ | $sd_device = $f[7]; | ||
+ | printf " | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | & | ||
+ | } | ||
+ | |||
+ | |||
+ | | ||
+ | # do volumes | ||
+ | sub get_vols { | ||
+ | my $arg; | ||
+ | | ||
+ | if ( $Options{g} ) { | ||
+ | if ( $arg >= 1 ) { | ||
+ | @dg_list=@ARGV; | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | # remember that getopts -v switch resets $#ARGV and @ARGV to only what comes after the " | ||
+ | # i.e. test for a " | ||
+ | my $arg; | ||
+ | $arg=scalar (@ARGV); | ||
+ | if ( $Options{v} ) { | ||
+ | if ( $arg < 1 ) { | ||
+ | @dg_vols=`/ | ||
+ | } else { | ||
+ | @dg_vols=@ARGV; | ||
+ | } | ||
+ | } else { | ||
+ | @dg_vols=`/ | ||
+ | } | ||
+ | | ||
+ | print "\nDG $dg \n"; | ||
+ | |||
+ | @sub_vol_parent_volname_array=(); | ||
+ | @sub_vol_parent_plexname_array=(); | ||
+ | @sub_vol_child_volname_array=(); | ||
+ | |||
+ | foreach $vol (@dg_vols) { | ||
+ | @dg_vol_array=`/ | ||
+ | @format=(); | ||
+ | @format=`/ | ||
+ | my @format2=split(" | ||
+ | my @format_pl=split(",", | ||
+ | $k=0; # count volumes | ||
+ | $pr=0; | ||
+ | @print_array=(); | ||
+ | $sub_vol_flag=" | ||
+ | # *** $# | ||
+ | # *** whereas " | ||
+ | while ($k <= $# | ||
+ | @vol_elements = split(" | ||
+ | if ($vol_elements[0] eq " | ||
+ | $reset_plex=" | ||
+ | $vol_size=($vol_elements[5]/ | ||
+ | $remember_vol=" | ||
+ | $remember_vol_array_no=" | ||
+ | # test whether volume is present in sub-vol array, if it is we won't output it yet | ||
+ | foreach $item (@sub_vol_child_volname_array) { | ||
+ | if ($vol_elements[1] eq $item) { | ||
+ | $sub_vol_flag=" | ||
+ | last; | ||
+ | } | ||
+ | } | ||
+ | } elsif ($vol_elements[0] eq " | ||
+ | if ( $reset_plex ne " | ||
+ | $vol_format=($vol_elements[6]); | ||
+ | if ( $vol_format eq " | ||
+ | $vol_format=" | ||
+ | } elsif ( $vol_format eq " | ||
+ | $vol_format=" | ||
+ | } elsif ( $vol_format eq " | ||
+ | $vol_format=" | ||
+ | } | ||
+ | } | ||
+ | $reset_plex=" | ||
+ | if (scalar (@format_pl) >=2 && $vol_format ne " | ||
+ | $vol_mir_format=" | ||
+ | # now overwrite our vol line now we know its format | ||
+ | $print_array[$remember_vol_array_no]=sprintf " | ||
+ | } else { | ||
+ | $vol_mir_format=""; | ||
+ | $print_array[$remember_vol_array_no]=sprintf " | ||
+ | } | ||
+ | unless ( $Options{s} ) {$print_array[$pr]=sprintf " | ||
+ | $remember_plex=" | ||
+ | $get_plex_log=" | ||
+ | } elsif ($vol_elements[0] eq " | ||
+ | $sub_vol_flag=" | ||
+ | $sub_vol_child_volname=" | ||
+ | $sub_vol_parent_plex=" | ||
+ | $sub_vol_parent_vol=" | ||
+ | push(@sub_vol_parent_volname_array, | ||
+ | push(@sub_vol_parent_plexname_array, | ||
+ | push(@sub_vol_child_volname_array, | ||
+ | push(@$remember_vol, | ||
+ | } elsif ($vol_elements[0] eq " | ||
+ | $size=($vol_elements[5]/ | ||
+ | if ($vol_elements[6] eq " | ||
+ | unless ( $Options{s} ) {$print_array[$pr]=sprintf " | ||
+ | } # if vol_elements | ||
+ | ++$k; # k=number of volumes | ||
+ | ++$pr; # pr=load print array | ||
+ | } # while $k <= $# | ||
+ | |||
+ | # print out our data... | ||
+ | $l=0; | ||
+ | while ($l <= $pr) { | ||
+ | if ( $sub_vol_flag ne " | ||
+ | print " | ||
+ | } | ||
+ | ++$l; # l=unload print array | ||
+ | } # while $l <= $pr | ||
+ | |||
+ | } # foreach @dg_vols | ||
+ | |||
+ | # now process all data for layered volumes... | ||
+ | |||
+ | %seen = (); | ||
+ | @unique_sub_vol_parent_volname_array=(); | ||
+ | foreach $item (@sub_vol_parent_volname_array) { | ||
+ | | ||
+ | } # foreach item | ||
+ | |||
+ | %seen = (); | ||
+ | @unique_sub_vol_parent_plexname_array=(); | ||
+ | foreach $item (@sub_vol_parent_plexname_array) { | ||
+ | | ||
+ | } # foreach item | ||
+ | |||
+ | if ( scalar (@unique_sub_vol_parent_volname_array) >= 1 ) { | ||
+ | $mm=0; | ||
+ | foreach $svp (@unique_sub_vol_parent_volname_array) { | ||
+ | #print " | ||
+ | my $nn=0; | ||
+ | @svp_vol_array=(); | ||
+ | @svp_vol_array=`/ | ||
+ | while ($nn <= $# | ||
+ | @vol_elements3 = split(" | ||
+ | if ( scalar (@$svp) == 1 ) { | ||
+ | $format=" | ||
+ | } else { | ||
+ | $format=" | ||
+ | } | ||
+ | my $size=($vol_elements3[5]/ | ||
+ | if ($vol_elements3[0] eq " | ||
+ | printf " | ||
+ | } elsif ($vol_elements3[0] eq " | ||
+ | unless ( $Options{s} ) {printf " | ||
+ | } | ||
+ | ++$nn; | ||
+ | } | ||
+ | |||
+ | foreach $svv (@$svp) { | ||
+ | $n=0; | ||
+ | @sv_vol_array=(); | ||
+ | @sv_vol_array=`/ | ||
+ | while ($n <= $# | ||
+ | @vol_elements2 = split(" | ||
+ | my $size=($vol_elements2[5]/ | ||
+ | if ($vol_elements2[5] eq " | ||
+ | if ($vol_elements2[0] eq " | ||
+ | printf " | ||
+ | } elsif ($vol_elements2[0] eq " | ||
+ | unless ( $Options{s} ) {printf " | ||
+ | } elsif ($vol_elements2[0] eq " | ||
+ | #if ($vol_elements2[6] eq " | ||
+ | unless ( $Options{s} ) {printf " | ||
+ | } # if | ||
+ | ++$n; | ||
+ | } # while | ||
+ | } # foreach $svv (@$svp) | ||
+ | ++$mm; | ||
+ | } # foreach unique_sub_vol_parent_volname_array | ||
+ | } # if scalar unique_sub_vol_parent_volname_array | ||
+ | } # foreach (@dg_list) | ||
+ | } # sub get_data | ||
+ | |||
+ | |||
+ | sub do_usage { | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | } | ||
+ | |||
+ | sub do_help { | ||
+ | print " | ||
+ | print "\n1. concat\n"; | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print "\n2. stripe = (raid-0)\n"; | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print "\n3. mirror = (raid-1)\n"; | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print "\n4. raid = (raid-5)\n"; | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print "\n5. mirrored-stripe = (raid-0+1)\n"; | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print "\n6. [layered volume] - striped-mirror (\" | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print "\n7. [layered volume] - concat-mirror (\" | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | print " | ||
+ | } | ||
+ | |||
+ | sub get_bighelp { | ||
+ | `man vxintro`; | ||
+ | } | ||
+ | |||
+ | sub get_version { | ||
+ | $version=`swlist -l product VRTSvxvm | grep VRTSvxvm | awk ' | ||
+ | print " | ||
+ | } | ||
+ | |||
+ | & | ||
+ | |||
+ | %Options; | ||
+ | getopts(' | ||
+ | |||
+ | |||
+ | if ( $Options{v} ) { | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | } elsif ( $Options{d}) { | ||
+ | & | ||
+ | & | ||
+ | } elsif ( $Options{g}) { | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | } elsif ( $Options{a}) { | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | } elsif ( $Options{s}) { | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | } elsif ( $Options{h}) { | ||
+ | & | ||
+ | } elsif ( $Options{H}) { | ||
+ | & | ||
+ | } elsif ( $Options{V}) { | ||
+ | & | ||
+ | } else { | ||
+ | & | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | ############################################################################## | ||
+ | ### This script is submitted to BigAdmin by a user of the BigAdmin community. | ||
+ | ### Sun Microsystems, | ||
+ | ### contents or the code enclosed. | ||
+ | ### | ||
+ | ### | ||
+ | ### Copyright Sun Microsystems, | ||
+ | ### Use of this software is authorized pursuant to the | ||
+ | ### terms of the license found at | ||
+ | ### http:// | ||
+ | ############################################################################## | ||
+ | </ |