Question about an expect script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question about an expect script
# 1  
Old 02-25-2009
Question about an expect script

I am using Expect to spawn a command that loops through a text file and runs the same command for each item in the text file.

The text file, named stat.txt looks something like this:

2007-04 alist 543
2008-07 blist 543
2008-03 xlist 345
2008-03 ylist 675
2003-03 zlist 567

The expect script looks like this:


set timeout 600
set input [open "/tmp/stat.txt" "r"]

while {[gets $input line] != -1} {

# separates agency code from listname

set datecreated [lindex $line 0]
set listname [lindex $line 1]
set agency [lindex $line 2]

set newfile $listname.members.$agency.$datecreated
spawn /usr/local/mailman/bin/list_members -o /tmp/lists/test/$newfile $listname

close $input

The script looks at the 'listname' field in the text file, spawns the command 'list_members' for each one and creates a separate file for each, containing the email addresses of those on the list.

The script works as I want until it gets to the listname beginning with 'y'. When I run the script, I see the spawning until the end, as if it actually creates a file for each listname. However, when I do a listing on /tmp/lists/test, there are no files beyond the 'x' name. Is there a way I can see why the spawn is not working for those particular items, even though it appears that it is?

# 2  
Old 02-25-2009
Try running with "expect-d" option or include "exp_internal 1" in the code. Either will turn on debugging and may give a clue as to what's happening.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Expect Question

I'm using expect to log into a remote host and then execute another script. A log of the script is being created but I can't see to get the script to display while it's running. Any ideas would be appreciated. Here is the script. #!/bin/bash cd /root cat /root/hostname1.txt | while read... (1 Reply)
Discussion started by: jimmyf
1 Replies

2. UNIX for Beginners Questions & Answers

Expect Question

Have an expect script but can't seem to de-bug it. It's stalling at the password prompt. If anyone can see a mistake, kindly let me know. Thanks. Here is the error: spawn ssh -o StrictHostKeyChecking=no user@xx.xx.xx.xx rpm -qa # Warning! You have entered into a secured area! # # All... (2 Replies)
Discussion started by: jimmyf
2 Replies

3. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies

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

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

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

7. Shell Programming and Scripting

Expect question

Hi all, I have got a small expect script like this one. #!/usr/bin/expect -f set timeout 2 spawn ftp $env(IP) match_max 100000 expect -exact "Name" send -- "$env(USER)\n" expect -exact "Password:" send -- "$env(PASSWORD)\n" expect "%" send "bin\r" expect "%" send "prompt\r"... (5 Replies)
Discussion started by: stinkefisch
5 Replies

8. Shell Programming and Scripting

Telnet Expect script question

Hi all, I have written a small expect script which should spawn a telnet session login and execute some commands. #!/usr/bin/expect -f spawn telnet $env(IP) match_max 100000 expect "login:" send -- "******\n" expect -exact "Password:" send -- "****\n" expect "%" Now I have got... (2 Replies)
Discussion started by: stinkefisch
2 Replies

9. Shell Programming and Scripting

question about "sleep" command in expect script

I wrote some expect script to telnet to some device to execute some commands.Firstly,I can't get full result some time,then I try to add some "sleep" command in it.Fortunately it works. My idea about it is that it uses sleep command to wait the result to be displayed.Am I right or correct the... (4 Replies)
Discussion started by: robbiezr
4 Replies

10. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies
Login or Register to Ask a Question

Featured Tech Videos