467,113 Members | 1,392 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,113 developers. It's quick & easy.

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



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...

Expand|Select|Wrap|Line Numbers
  1. #!/bin/ksh
  2. set klug { ${1+"$@"}
  3. shift
  4. shift
  5.   exec /usr/bin/expect -f $0 ${1+"$@"}
  6. }
  7. set ip [lindex $argv 0 ]
  8. set file [lindex $argv 1]
  10. spawn ssh -o stricthostkeychecking=no root@$ip
  11. expect -re "Password"
  12. send "password\r"
  13.  set fp [open $file ]
  14.      while {-1 != [gets $fp line]} {
  15.          send  "$line\r"
  16.      }
  17. interact
Aug 4 '08 #1
  • viewed: 1694
5 Replies
Expert Mod 2GB
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.


Aug 4 '08 #2
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...

Changes Expect.pod META.yml Pty.pm Tty.pm test.pl
Expect.pm MANIFEST Makefile.PL README examples tutorial
Aug 4 '08 #3
Any Info on Modifying the Expect script or Installing the Module will be helpfull....
Aug 5 '08 #4
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;
Aug 6 '08 #5
Expert Mod 2GB
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
Expand|Select|Wrap|Line Numbers
  1. 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.


Aug 6 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

385 posts views Thread by Xah Lee | last post: by
1 post views Thread by graphman | last post: by
reply views Thread by seanovision | last post: by
1 post views Thread by vikjohn | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.