Need Info on EXPECT and PERL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kriz4321
    New Member
    • Jan 2007
    • 48

    Need Info on EXPECT and PERL

    I call a EXPECT script from my perl script with machine IP and a FIle. The script logins to the machine and exports the value. I have close to 10 machines and I have created 10 files and pass the corresponding files in command line.

    I could like to do this with a sinle file. I will create a file as below

    MAchine1
    EXPORT VAR1=
    EXPORT VER2=
    EXPORT VAR3=
    MAchine1

    Machine2
    EXPORT VAR1=
    EXPORT VER2=
    EXPORT VAR3=
    MAchine2


    Now I need to take the Info present between machine1 and store it an array and then pass it to expect script. I can take the values in an array but not sure how to use the values stored in array and use it in EXPECT script.. Any pointers will be helpful...

    Code:
    #!/bin/ksh
    set klug { ${1+"$@"}
    shift
    shift
      exec /usr/bin/expect -f $0 ${1+"$@"}
    }
    set ip [lindex $argv 0 ]
    set file [lindex $argv 1]
    
    spawn ssh -o stricthostkeychecking=no root@$ip
    expect -re "Password"
    send "password\r"
     set fp [open $file ]
         while {-1 != [gets $fp line]} {
             send  "$line\r"
         }
    interact
    Last edited by numberwhun; Aug 4 '08, 12:27 PM. Reason: Please use code tags
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Because you are calling another script, the only non-Perl thing I see you being able to do is modify the other script to take options from the command line. That way, when you call the script in the perl script, you can specify the options.

    For a Perl solution, you may want to check out the Perl Expect module. Its a bit involved, but you will be able to re-write the expect script and completely use Perl, without having to call an outside script from the system.

    Regards,

    Jeff

    Comment

    • kriz4321
      New Member
      • Jan 2007
      • 48

      #3
      Iam running on a Linux machine I which I have no root permission. I have downloaded the expect module. Iam adding the follwing line in my program

      use lib "/home/ID/Expect/Expect-1.21";
      use Expect;
      {
      }
      I shows Can't locate IO/Pty.pm in @INC BEGIN failed--compilation aborted at /home/ID/Expect/Expect-1.21/Expect.pm line 23.

      I Downloaded the above two .PM files and kept in the path but still it fails for the same resaon.(I have not executed any "make" command)....
      Please let me know If I have missed something here...

      /home/ID/Expect/Expect-1.21>ls
      Changes Expect.pod META.yml Pty.pm Tty.pm test.pl
      Expect.pm MANIFEST Makefile.PL README examples tutorial

      Comment

      • kriz4321
        New Member
        • Jan 2007
        • 48

        #4
        Any Info on Modifying the Expect script or Installing the Module will be helpfull....

        Comment

        • Ritusriv
          New Member
          • Jul 2008
          • 7

          #5
          If you want to include the module which are in the same directory where your binary is,then try this

          use FindBin qw($Bin);
          use lib "$Bin";
          use Pty;
          use Tty;
          ..............

          Comment

          • numberwhun
            Recognized Expert Moderator Specialist
            • May 2007
            • 3467

            #6
            Originally posted by kriz4321
            Any Info on Modifying the Expect script or Installing the Module will be helpfull....
            Is there any reason you do not use the CPAN installer to install the modules? Its much easier and can automatically install any and all dependencies so you don't have to worry about them.

            If you cannot, then you will have to do the following:

            1. Download the module.
            2. Unpack the module (as it will be a .tar.gz file)
            3. Go into the module directory and run
            Code:
            perl Makefile.pl
            That will produce the Makefile for the make command.

            4. Run "make"
            5. Run "sudo make test" (this will ensure that all installs ok before actually doing it)
            6. Run "sudo make install".

            If, during the make errors are spit out about dependencies, you will have to first download the each module dependency and install it seperately. This is why I like the CPAN installer, no need to really worry about all that.

            Regards,

            Jeff

            Comment

            Working...