Expect Script using the split command?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect Script using the split command?
# 1  
Old 08-03-2012
Expect Script using the split command?

Hello All,

I have an Expect Script that ssh'es to a server and does some stuff.
In Expect there is a built-in Array Variable called "expect_out(buffer)" which contains all the output from the previous send command up until the expected output.

I want to pass the array "expect_out(buffer)" to a Procedure/Function I have.
After I pass the array I have a loop that I use to loop through each element line by line.

I am able to successfully do this loop outside of the Procedure using that expect_out(buffer) array...
So how can I convert this code below, to use a new array variable argument in the procedure?
Code:
### This loop works outside of this procedure...
foreach line [split $expect_out(buffer) "\n"] {
          send_user "Line = $line\n"
}

So how can I basically do the same thing as above, but this time I have to change the split function to use this new Array Variable "outputArray" that had "expect_out(buffer)" passed into it?
Code:
proc save_outputBuffer { outputArray } {

    foreach line [ split *NEW ARRAY* "\n"] {
          send_user "LINE = $line\n"
    }

    return $outputArray

}

I've tried a couple of different ways to do the split command but nothing seems to work...

Any thoughts would be great!

Thanks in Advance,
Matt

Last edited by mrm5102; 08-03-2012 at 05:31 PM..
# 2  
Old 08-06-2012
Define proc like this:

Code:
proc save_outputBuffer { outputArray } {
    foreach line [ split $outputArray "\n" ] {
        send_user "LINE = $line\r\n"
    }
    return $outputArray
}

Call it like this:
Code:
set myArray [ save_outputBuffer $expect_out(buffer) ]

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 08-06-2012
Hey Chubler_XL, thanks for the reply!

I tried it like you have it inside the proc, but I definitely didn't call it like you had though.
I'll give that a try and post back....


Thanks Again,
Matt

---------- Post updated at 10:25 AM ---------- Previous update was at 09:31 AM ----------

Hey there again Chubler_XL...

I tried out your example and it works like a charm! Smilie
Thanks again for your help!


Thanks Again,
Matt
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

To send ID and Password for each command using expect feature in bash script

Dear Tech Guys, I am trying to send some commands on the local server and it always asks for user name and password after each command. To serve the purpose I am using expect function as follows: #!/usr/bin/expect set timeout 20 spawn "./data1.sh" expect "Please Enter UserName: "... (6 Replies)
Discussion started by: Xtreme
6 Replies

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

3. Shell Programming and Scripting

Can i use if else inside expect command in shell script?

hii,, I am trying to automate jira. during my scripting using bash script, in the terminal i got the terminal message like this: "Configure which ports JIRA will use. JIRA requires two TCP ports that are not being used by any other applications on this machine. The HTTP port is where you... (1 Reply)
Discussion started by: nithinfluent
1 Replies

4. Shell Programming and Scripting

help a beginner, expect script, command not found

hi, i have a problem with my expect script, here is MyScript: #!/usr/bin/expect set pass set c set command spawn sudo $command expect "assword" send "$pass\r" expect eof My problem is that when i execute MyScript with the command : "./MyScript mypassword apt-get_install_git"i get... (6 Replies)
Discussion started by: gongotar
6 Replies

5. Shell Programming and Scripting

Script using SSH with expect command

Hi all, I want to connect to some host with "ssh". I have googled and got some commands of "expect" and "spawn". I was not aware of these commands and tried below script. $ cat auto.sh set host xx.xx.xx.xx set password abcd@1234 set user root spawn ssh $user@$host expect "*?assword:*"... (4 Replies)
Discussion started by: divya bandipotu
4 Replies

6. Shell Programming and Scripting

simple php/expect script works from command line but not from web

I have a really basic expect script which I call from php. I works fine when I run the php from the shell, but from the web it appears as if the output buffer gets chopped and never gets all of the contents. php script: (runexpect.php) <?php... (7 Replies)
Discussion started by: jacksona2
7 Replies

7. Shell Programming and Scripting

Can 'spawn' command be used more than once in an expect script ?

Can 'spawn' script be used more than once in a given expect script ?? What I'm trying to do is, first log-into a remote server through one 'ssh' spawn com and then from there log-into another server using a secod 'ssh' spawn command. But this approach is not working... the second ssh attempt... (1 Reply)
Discussion started by: clakkad
1 Replies

8. Shell Programming and Scripting

Expect script: obtain the exit code of remote command

Hi all, I'm trying to run the sipp simulator in crontab but after some attempt I came to the conclusion that for some reason this isn't possible (maybe due to sipp interactive nature). This is confirmed by these posts. Now I'm trying to launch sipp from an expect script that runs in crontab. ... (0 Replies)
Discussion started by: Evan
0 Replies

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

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