Sponsored Content
Top Forums Shell Programming and Scripting Calling expect scripts from other expect scripts Post 302181656 by seva on Thursday 3rd of April 2008 01:45:54 PM
Old 04-03-2008
Calling expect scripts from other expect scripts

Hi,

First, let me explain the issue I am trying to solve. We have a lot of expect scripts with the duplicated send/expect commands. So, I'd like to be able to extract the duplicated code into the common scripts that can be used by other scripts.

Below is my test where I am trying to call b.exp from a.exp:

a.exp
#!/usr/bin/env expect
#
set timeout 5
spawn $env(SHELL)
match_max 100000

send -- "./b.exp $spawn_id\r"

expect "bla"
expect eof
exit

b.exp
#!/usr/bin/env expect
#
set spawn_id [lrange $argv 0 0]
send -- "ls -al\r"
expect bla

I am passing the spawn_id into the b.exp script and then sending the "ls" command. The "ls" command does not output anything, so I understand that I can't pass just like that the handle to the process from one expect script to the other.

Could you suggest any other approach to solve my original issue or maybe there's actually a way to talk to the same process from the distinct expect scripts?

Thanks,
Seva
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling Expect script in 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. The values to be exported or stored in a file. I have close to 10 machines and I have created 10 files and pass the corresponding files in command line, Now I could like... (4 Replies)
Discussion started by: ramkriz
4 Replies

2. Shell Programming and Scripting

How to handle scripts that expect an input

Hi I would like to know how to handle my script that expects an input when calling the script and the user doesn't enter anything, I need to re-direct to my helpfile. Bascically here is my script: #!/bin/bash csvdir="/var/local/dsx/csv/general" csvfile="$csvdir/$csvfile"... (3 Replies)
Discussion started by: ladyAnne
3 Replies

3. Shell Programming and Scripting

Need help using expect in shell scripts

hi all, i have this script that accepts passwords automatically and its working in one host only. my problem is how will i use it if i need it to run in more than one host/server let say by using "for loop statement" working : spawn bundle linux -r hostname checkpath... (2 Replies)
Discussion started by: linuxgeek
2 Replies

4. UNIX for Dummies Questions & Answers

Difference between using Here document and Expect in scripts

Hi, I am confused between using here document and using expect for writing interactive shell scripts(like changing password ,FTP or doing su). My questions are : 1)Why here documents cant change password from shell script. 2)Why we need to use expect for same? 3) Can Sourcing a script can do... (2 Replies)
Discussion started by: kailash19
2 Replies

5. Shell Programming and Scripting

Calling scripts from with scripts

Hi all, I'm wondering if you could give me some advice. I am new to scripting and am getting rather frustrated that i can get my script to call another script if certain criteria is met, via command line, but I cannot get the same script to work thru the cron jobs. My first script monitors... (8 Replies)
Discussion started by: echoes
8 Replies

6. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

7. Shell Programming and Scripting

Using Expect scripts to port files to different unix box

Hello all, I've been trying to design a script which will help me transfer files from one unix box to another. Following is the code: #!/usr/local/bin/expect spawn /usr/bin/scp ms_cp5_daily.ksh userid@cat:/prod/env/ms.txt set pass xxxxxx expect { password: {send "$pass\r";... (4 Replies)
Discussion started by: sethmj
4 Replies

8. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

9. Shell Programming and Scripting

Calling multiple scripts from another scripts

Dear all, I am working on script which call other shell scripts in a loop but problem is from second script am not able to come out. Here is the snippet:- #!/bin/bash HSFILE=/root/Test/Components.txt LOGFile=/opt/domain/AdminDomain/application/logs... (3 Replies)
Discussion started by: sharsour
3 Replies

10. Shell Programming and Scripting

Scripts triggered via 'expect' - stderr lost

I have a bash script on server that runs fine when run interactively and writes stderr output to a file. However, when invoked through a 'expect' script run on Mac OS my laptop which does ssh to the server : generates the expected file, but file has no content. I suspect the stderr is getting... (1 Reply)
Discussion started by: sdudc
1 Replies
NewtonRaphson(3pm)					User Contributed Perl Documentation					NewtonRaphson(3pm)

NAME
Math::Calculus::NewtonRaphson - Algebraic Newton Raphson Implementation SYNOPSIS
use Math::Calculus::NewtonRaphson; # Create an object. my $exp = Math::Calculus::NewtonRaphson->new; # Set a variable and expression. $exp->addVariable('x'); $exp->setExpression('x^2 - 5') or die $exp->getError; # Apply Newton Raphson. my $result = $exp->newtonRaphson(2) or die $exp->getError; print $result; # Prints 1.4142... DESCRIPTION
This module can take an algebraic expression, parses it and then uses the Newton Raphson method to solve the it. The Newton Raphson method relies on the fact that the expression you pass in evaluates to zero where there is a solution. That is, to solve:- x^2 = 5 You would need to pass in:- x^2 - 5 It understands expressions containing any of the operators +, -, *, / and ^ (raise to power), bracketed expressions to enable correct precedence and the functions ln, exp, sin, cos, tan, sec, cosec, cot, sinh, cosh, tanh, sech, cosech, coth, asin, acos, atan, asinh, acosh and atanh. EXPORT
None by default. METHODS
new $exp = Math::Calculus::NewtonRaphson->new; Creates a new instance of the Newton Raphson object, which can hold an individual expression. addVariable $exp->addVariable('x'); Sets a certain named value in the expression as being a variable. A named value must be an alphabetic chracter. setExpression $exp->setExpression('x^2 + 5*x); Takes an expression in human-readable form and stores it internally as a tree structure, checking it is a valid expression that the module can understand in the process. Note that the engine is strict about syntax. For example, note above that you must write 5*x and not just 5x. Whitespace is allowed in the expression, but does not have any effect on precedence. If you require control of precedence, use brackets; bracketed expressions will always be evaluated first, as you would normally expect. The module follows the BODMAS precedence convention. Returns undef on failure and a true value on success. getExpression $expr = $exp->getExpression; Returns a textaul, human readable representation of the expression that is being stored. newtonRaphson $result = $exp->newtonRaphson($variable, $guess, %mappings); Attempts to solve the expression for the given variable using the Newton Raphson method, using the passed value as the first guess. The mappings hash allows any other non-numeric constants to be mapped to numeric values - a pre-requisite for solving such equations. getTraceback $exp->getTraceback; When setExpression and newtonRaphson are called, a traceback is generated to describe what these functions did. If an error occurs, this traceback can be extremely useful in helping track down the source of the error. getError $exp->getError; When any method other than getTraceback is called, the error message stored is cleared, and then any errors that occur during the execution of the method are stored. If failure occurs, call this method to get a textual representation of the error. SEE ALSO
The author of this module has a website at <http://www.jwcs.net/~jonathan/>, which has the latest news about the module and a web-based frontend to allow you to test the module out for yourself. AUTHOR
Jonathan Worthington, <jonathan@jwcs.net> COPYRIGHT AND LICENSE
Copyright (C) 2004 by Jonathan Worthington This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available. POD ERRORS
Hey! The above document had some coding errors, which are explained below: Around line 65: '=item' outside of any '=over' Around line 186: You forgot a '=back' before '=head1' perl v5.10.0 2008-06-13 NewtonRaphson(3pm)
All times are GMT -4. The time now is 02:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy