TCL expect out string with multiple lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting TCL expect out string with multiple lines
# 1  
Old 08-16-2012
TCL expect out string with multiple lines

Hello,

I will be sending this command to a specific COMID:
Code:
exp_send-i  $COMID "fdisk -l | grep Disk | awk '{print $2}'"

The command will produce this output:
Code:
/dev/sda
/dev/sdb
etc..

the problem is how do I store the output in a variable in TCL,

I am currently using this to grab the text:
Code:
expect -i $COMID -re "(\[A-Za-z]+)" {
    set disks $expect_out(1,string)
}
puts "disks = $disks"

but I can only get 1 string from the command; output is like this:
Code:
"disks = fdisk"

thanks!!

---------- Post updated Aug 16th, 2012 at 01:32 PM ---------- Previous update was Aug 15th, 2012 at 01:44 PM ----------

no reply? Smilie

---------- Post updated Aug 17th, 2012 at 09:12 AM ---------- Previous update was Aug 16th, 2012 at 01:32 PM ----------

anyone?

Last edited by Franklin52; 08-15-2012 at 04:17 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 08-16-2012
Try something like this:

Code:
send "fdisk -l | grep Disk | awk '{print \$2}'; echo NOW_DONE\r"
expect -r ".*echo NOW_DONE\r\n(.*)\nNOW_DONE" {
        set disks $expect_out(1,string)
}
puts "disks = $disks"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

2. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

3. Shell Programming and Scripting

expect TCL script

Hello, I write a TCL script for Expect/ Telnet. I want to send command to the telnet server. But I want to close after the command is sent. Anybody know which command can flush the expect so I can sure the command is sent to the telnet server??? EX: send "./command1\r" close... (0 Replies)
Discussion started by: linboco
0 Replies

4. UNIX for Dummies Questions & Answers

Expect/Tcl help

hi, I am new in Expect. I have a question about expect timeout. suppose I have a structure of expect { ".."{ send"............"} timeout{ ............... } } The silly question is if I reach timeout, how can I store the error message showing on the screen to... (2 Replies)
Discussion started by: allenxiao7
2 Replies

5. Shell Programming and Scripting

TCL/Expect not working as expected

I am having an issue with TCL\Expect; I am passing arguments via the commandline that are read in via "lrange $argv". One of those var's is a password with characters that need to be escapaed, after escaping them an hitting enter expect is placing curly braces around my password... why?! ... (4 Replies)
Discussion started by: RiSk
4 Replies

6. Shell Programming and Scripting

Help with TCL/Expect in Solaris 5.3

I'm having this problem with a very simple tcl expect script that is running on Solaris 5.3 with TCL version 8.4.7 and expect version 5.0. below is the simplified version of the code snippet, which I think has everything to illustrate the problem, the full version is at the very bottom in... (0 Replies)
Discussion started by: pinchharmonic
0 Replies

7. Shell Programming and Scripting

tcl/expect

Can someone identify what is the problem here?. no children while executing "exp_wait -nowait -i -1" (procedure "logOptions" line 45) invoked from within "logOptions" (procedure "doExecute" line 98) invoked from within "doExecute" (procedure "main" line 32) ... (7 Replies)
Discussion started by: calsum
7 Replies

8. Shell Programming and Scripting

Tcl expect HELP

In the following "for" loop I assume the the script will expect "anyway", "first" NOT in any paticular order and send "yes" when there found, breaking out of the loop when "$prompt" is found. The way it is working is like 3 individual expect lines, and they MUST be in cronological order. ANY help... (0 Replies)
Discussion started by: dave_m
0 Replies

9. UNIX for Dummies Questions & Answers

Expect/Tcl help?

Does anyone know of an expect/tcl forum that is as helpful as this one is for shell scripting? Or if anyone has any expect knowledge, can you please provide some guidance on how to write to a local error log based on output from a ssh session? I have something like this: foreach host... (2 Replies)
Discussion started by: earnstaf
2 Replies

10. Shell Programming and Scripting

Expect with tcl/tk

hai all, i have an tcl script in which i have been reading the DUT Command prompt of an cisco switch as DUT Command Prompt : cisco* and running the test case of stp now the problem is if i have given any blank space in between the cisco or at the startup then the Expect is not identifying the... (0 Replies)
Discussion started by: sanjustudy
0 Replies
Login or Register to Ask a Question