Script interactif

De BlaxWiki
Aller à la navigationAller à la recherche

Lorsque l'on veut automatiser des installations, il arrive que certain programme pose des questions, et qu'il n'est pas possible d'y répondre automatiquement en utilisant des commandes classiques (comme echo -e "YES\n\n y" | script.sh). On peut alors utiliser la commande expect est un outil d’automatisation de tâches Unix, pour des applications interactive comme ssh, telnet, ftp, passwd, fsck ou autre. Il utilise le langage de script Tcl et fonctionne depuis n’importe quel Unix et windows.

Voici un exemple pour la commande mysql_config_editor.

  • Script expect_script_mysql
#!/usr/bin/expect

spawn mysql_config_editor set --login-path=local --host=localhost --user=localuser2 --password
expect "assword"
send "TopSecret\r"
expect "ontinue"
send "Y\r"
expect eof
  • Commande en mode manuel
#  mysql_config_editor set --login-path=local --host=localhost --user=localuser2 --password
Enter password:
WARNING : 'local' path already exists and will be overwritten.
 Continue? (Press y|Y for Yes, any other key for No) : y
  • Commande avec expect
# ./expect_script_mysql
spawn mysql_config_editor set --login-path=local --host=localhost --user=localuser2 --password
Enter password:
WARNING : 'local' path already exists and will be overwritten.
 Continue? (Press y|Y for Yes, any other key for No) : Y