LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-29-2009, 01:50 PM   #1
spoofedexistence
LQ Newbie
 
Registered: Jul 2006
Posts: 5

Rep: Reputation: 0
Unhappy Using an expect Script to send the output of cat and append it to a file


So basically I want to append and not overwrite the output of "cat slabdebug" to outputfile.txt. Currently if I run this I do get the output written to outputfile.txt and the loop works correctly till reaching 51 but it overwrites the file and does not append it. Please help and let me know if what I want to accomplish is possible.

#!/usr/bin/expect
set timeout 10
spawn telnet <ipaddressofmymachine>
match_max 100000
sleep 2
expect "login: "
send "admin\r"
expect "password: "
send "\r"
expect "*#"
send "cd /proc\r"
expect "*#"
set i 1
while {$i < 51} {
set output [open "outputfile.txt" "w"]
sleep 2
send "cat slabdebug\n"
expect "*#"
set outcome $expect_out(buffer)
send "\r"
puts $output $outcome
incr i
}
close $output
expect "*#"
expect eof


thanks
 
Old 09-29-2009, 03:50 PM   #2
spoofedexistence
LQ Newbie
 
Registered: Jul 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Got it

After reading I figured that changing

set output [open "outputfile.txt" "w"]
to
set output [open "outputfile.txt" "a+"]

it now works.
 
  


Reply

Tags
expect, linux, tcl


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 09:06 PM
Can't get expect to work. send will not display an output edomingox Linux - General 7 07-14-2009 12:04 AM
expect script output don___quixote Linux - Newbie 5 07-06-2009 09:24 AM
expect script output saltydog4791 Programming 1 05-27-2008 08:01 AM
Expect script - No output to file pandersson61 Programming 4 05-23-2007 05:18 AM


All times are GMT -5. The time now is 04:41 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration