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
|