473,396 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
5 1893
numberwhun
3,509 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.

Regards,

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

/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
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
numberwhun
3,509 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
  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

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

Similar topics

7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
385
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
13
by: gavino | last post by:
This seems easy but I have been asking tcl and python IRC chat all day and no one gave an answer. I have 100 servers which need a new backup server added to a text file, and then the backup agent...
1
by: graphman | last post by:
I have a perl script that I'm calling using php's shell_exec that uses an expect module to go to another system to pull tiff files. The php perl combination works great when I launch from the...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
4
by: blackice | last post by:
Hello All, i have a Perl Script that deleting Zones from named.conf file and here is the script #!/usr/bin/perl -w use strict; print "please enter the domain name: "; chomp (my...
0
by: seanovision | last post by:
Hi, I've been wrestling with this for a few days and I'm not sure what I'm doing wrong. I'm writing a script that will eventually sign several certificate signing requests (CSRs) using openssl....
1
by: vikjohn | last post by:
I have a new perl script sent to me which is a revision of the one I am currently running. The permissions are the same on each, the paths are correct but I am getting the infamous : The specified...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.