Réponses:
ssh est plus facile que telnet:
for host in host1 host2 host3; do
ssh user@host remote_command with args
done > result.file
Pour une connexion sans mot de passe, configurez les clés ssh
Cela aura des bugs, mais quelque chose comme:
#!/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