ssh é mais fácil que o telnet:
for host in host1 host2 host3; do
ssh user@host remote_command with args
done > result.file
Para login sem senha, configure as chaves ssh
Isso terá bugs, mas algo como:
#!/usr/bin/env expect
exp_internal 1
set out [open "results.txt" w]
foreach ip $argv {
spawn telnet $ip
expect "password: "
send "$password\r"
expect "% " ;# this is the prompt, adjust to suit
sent "the command\r"
expect -re "([01,]+).*% "
puts $out "$ip=$expect_out(1,string)"
send exit
expect eof
exp_close
wait
}
close $out