Calling expect scripts from other expect scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling expect scripts from other expect scripts
# 1  
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
Login or Register to Ask a Question
opx25(1M)																 opx25(1M)

NAME
opx25 - execute HALGOL programs SYNOPSIS
scriptname] char] file-descriptor] file-descriptor] string] DESCRIPTION
The commands, including are targeted for removal from HP-UX; see the below. HALGOL is a simple language for communicating with devices such as modems and X.25 PADs. It has simple statements similar to and that are described below. Options recognizes the following options: Causes to read script as the input program. If is not specified, reads the standard input as a script. Causes to use char as the first character in the input stream instead of actually reading it from the input descriptor. This is useful sometimes when the program that calls is forced to read a character but then cannot ``unread'' it. Causes to use number for the output file descriptor (i.e., the device to use for The default is 1. Causes to use 'number' for the input file descriptor (ie, the device to use for 'expect'). The default is 0. Causes to save this string for use when is encountered in a command. Causes to turn on debugging mode. Causes to turn on verbose mode. An script file contains lines of the following types: (empty) Empty lines are ignored. Lines beginning with a slash are ignored (comments) ID ID denotes a label, and is limited to alphanumerics or string must be surrounded by double quotes. The text is sent to the device specified by the option. Non-printable charac- ters are represented as in C; i.e., as DDD, where DDD is the octal ascii character code. in a send string is the string that followed the option. Send a break "character" to the device. Here number is how many seconds to wait before giving up. 0 means wait forever, but this is not advised. Whenever string appears in the input within the time allotted, the command succeeds. Thus, it is not necessary to specify the entire string. For example, if you know that the PAD will send several lines followed by an prompt, you could just use as the string. The program etc.) is run with the args specified. Do not use quotes here. Also, the program is invoked directly (using so wild cards, redirection, etc. are not possible. If the most recent expect or run encountered an error, go to the label ID. Similar to but does not fork. Similar to but goes to standard error instead of to the device. Sets the program in debug mode. It echoes each line to as well as giving the result of each expect and run. This can be useful for writing new scripts. The command disables this feature. Sends subsequent incoming characters to This can be used in the file as a security measure, because part of the incoming data stream contains the number of the caller. There is a similar feature in it writes the time and the login name into the same logfile. The command disables this feature. Similar to but better in some cases because it sends only digits to the log file, and not other characters. The command dis- ables this feature. Sets a global timeout value. Each expect uses time in the timeout reservoir; when this time is gone, the program gives up (exit 1). If this com- mand is not used, there is no global timeout. Also, the global timeout can be reset any time, and a value of 0 turns it off. Exits with this value. 0 is success; anything else is failure. To perform a rudimentary test of configuration files, run by hand, using the option followed by the name of the script file. then sends to standard output and expects from standard input; thus you can type the input, observe the output, and use the command to see messages. See the file for a good example of HALGOL programming. WARNINGS
Use of commands, including is discouraged because they are targeted for removal from HP-UX. Use ftp(1) or rcp(1) instead. AUTHOR
was developed by HP. SEE ALSO
getx25(1), uucp(1). TO BE OBSOLETED opx25(1M)