By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,541 Members | 1,525 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,541 IT Pros & Developers. It's quick & easy.

Need Info on EXPECT and PERL

P: 48
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...

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]
  9.  
  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
  18.  
Aug 4 '08 #1
Share this Question
Share on Google+
5 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
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
Aug 4 '08 #2

P: 48
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
Aug 4 '08 #3

P: 48
Any Info on Modifying the Expect script or Installing the Module will be helpfull....
Aug 5 '08 #4

P: 7
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

numberwhun
Expert Mod 2.5K+
P: 3,503
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
  2.  
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
Aug 6 '08 #6

Post your reply

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