Embebed Perl Error

David
2012-09-20
2013-04-23
  • David
    David
    2012-09-20

    Hi David,

    I was the person who asked you for the remote scripting funcionality.
    I got a problem building the scripts i need, and i want to ask you some questions.

    The main goal is to run severals pings inside a cisco device to test the local reachabilty. All these ip address are inside the file hosts.txt i built. This file has the format "<name> <ipaddress>".

    This is the script i can run inside my local machine:

    #!/usr/bin/perl

    use Net::Ping;

    for (;;) {
    sleep 3;
    system('clear');

    open (HOSTS, "hosts.txt");

    while($HOSTS_ln = <HOSTS>){
    chop($HOSTS_ln);
    @HOSTS_wrds = split(/ /, $HOSTS_ln);
    # print "\nNueva Linea : @HOSTS_wrds\n";
    # print "mnemonico : @HOSTS_wrds\n";
    # print "dirip. : @HOSTS_wrds\n";

        $p = Net::Ping->new(icmp);
    print "@HOSTS_wrds \n" if not $p->ping(@HOSTS_wrds,1);
        $p->close();

    }
    close HOSTS;
    print "\nTerminado el Barrido \n";
    }

    When i tried to run inside the PAC, i got several errors, i dont understand.
    So i needed to switch back to my old SecureCRT where i run this other vb script:
    (as you can see, i added some extra functions to the Perl one.)

    Sub Main
    ' Definicion de Ficheros
    Const HOSTS_FILE_PATH = "D:\hosts.txt"
    Const RESULT_FILE_PATH = "D:\Result.txt"

    ' Dimensionamiento de Variables
    Dim Hosts_fso
    Set Hosts_fso = CreateObject("Scripting.FileSystemObject")
    Dim Result_fso
    Set Result_fso = CreateObject("Scripting.FileSystemObject")

    ' Apertuura de Ficheros
    Dim Hosts_file
    Set Hosts_file = Hosts_fso.OpenTextFile(HOSTS_FILE_PATH)
    Dim Result_file
    Set Result_file = Result_fso.OpenTextFile(RESULT_FILE_PATH,2,True)

    Dim ip
    Dim name
    Dim line
    While Not Hosts_file.AtEndOfStream
    line = Hosts_file.ReadLine

    name = Split(line, " ")(0)
    ip = Split(line, " ")(1)

    ' Connect
    crt.Screen.Synchronous = True

    ' Ping a un equipo
    crt.Screen.WaitForString "<name>#"
    crt.Screen.Send "ping vrf VPN_GESTION " & ip & " repeat 3" & vbCr

    ' Análisis de resultado y escritura
    icmp_result = crt.Screen.WaitForStrings ("rate is 33","rate is 66", "rate is 0","rate is 100")
    Select Case icmp_result
    Case 1,2
    Result_file.Write name & " " & ip & " Partial-Ok" & vbcrlf

    Case 3
    Result_file.Write name & " " & ip & " NOk" & vbcrlf

    Case 4
    Result_file.Write name & " " & ip & " Ok" & vbcrlf

    End Select

    Wend

    Hosts_file.Close
    Result_file.Close
    End Sub

    Could you help me to get the goal i wanted to reach?
    I would love to migrate the vbscript to Perl, but working inside the PAC.

    Regards,

    David