LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Using an expect Script to send the output of cat and append it to a file (https://www.linuxquestions.org/questions/programming-9/using-an-expect-script-to-send-the-output-of-cat-and-append-it-to-a-file-758493/)

spoofedexistence 09-29-2009 01:50 PM

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

spoofedexistence 09-29-2009 03:50 PM

Got it
 
After reading I figured that changing

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

it now works.


All times are GMT -5. The time now is 12:36 PM.