Bonjour,
j'aimerai me connecter à un switch depuis un script shell et y passer mes commandes de configuration, j'ai fait des recherche et j'ai pu voir que je pouvais utiliser soit expect ou telnet netcat. et ça donne ceci en telnet:
telnet mon_hostname << EOF
login
password
enable
password (si password enable)
conf t
etc.
EOF
je n'ai pas encore testé.
sinon l'utilitaire expect m'a l'air intéressant car permet d'avoir un retour, mais je ne le comprends pas du tout.
quelqu'un peut me dire si le bout de code ci dessus marcherai correctement, sinon que faut t'il rectifier?
Aussi j'ai trouvé sur Wiki ce bout de code concernant expect mais j'aimerai que quelqu'un m'explique exactement comment cet utulitaire marche et si poss les paramètres.
Voici le bout de code :
# Assume $remote_server, $my_user_id, $my_password, and $my_command were read in earlier
# in the script.
# Open a telnet session to a remote server, and wait for a username prompt.
spawn telnet $remote_server
expect "username:"
# Send the username, and then wait for a password prompt.
send "$my_user_id\r"
expect "password:"
# Send the password, and then wait for a shell prompt.
send "$my_password\r"
expect "%"
# Send the prebuilt command, and then wait for another shell prompt.
send "$my_command\r"
expect "%"
# Capture the results of the command into a variable. This can be displayed, or written to disk.
set results $expect_out(buffer)
# Exit the telnet session, and wait for a special end-of-file character.
send "exit\r"
Merci pour toute aide.
Phi.
Partager