Différences entre les versions de « Script interactif »
De BlaxWiki
Aller à la navigationAller à la recherche| Ligne 1 : | Ligne 1 : | ||
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 | 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, | 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 | ||
telnet, ftp, passwd, fsck ou autre. Il utilise le langage de script Tcl et fonctionne depuis n’importe quel Unix et windows. | 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. | Voici un exemple pour la commande mysql_config_editor. | ||
* Script expect_script_mysql | * Script expect_script_mysql | ||
<pre> | |||
#!/usr/bin/expect | #!/usr/bin/expect | ||
| Ligne 15 : | Ligne 15 : | ||
send "Y\r" | send "Y\r" | ||
expect eof | expect eof | ||
</pre> | |||
* Commande en mode manuel | * Commande en mode manuel | ||
<pre> | |||
# mysql_config_editor set --login-path=local --host=localhost --user=localuser2 --password | # mysql_config_editor set --login-path=local --host=localhost --user=localuser2 --password | ||
Enter password: | Enter password: | ||
WARNING : 'local' path already exists and will be overwritten. | WARNING : 'local' path already exists and will be overwritten. | ||
Continue? (Press y|Y for Yes, any other key for No) : y | Continue? (Press y|Y for Yes, any other key for No) : y | ||
</pre> | |||
* Commande avec expect | * Commande avec expect | ||
<pre> | |||
# ./expect_script_mysql | # ./expect_script_mysql | ||
spawn mysql_config_editor set --login-path=local --host=localhost --user=localuser2 --password | spawn mysql_config_editor set --login-path=local --host=localhost --user=localuser2 --password | ||
| Ligne 32 : | Ligne 32 : | ||
WARNING : 'local' path already exists and will be overwritten. | WARNING : 'local' path already exists and will be overwritten. | ||
Continue? (Press y|Y for Yes, any other key for No) : Y | Continue? (Press y|Y for Yes, any other key for No) : Y | ||
</pre> | |||
[[Catégorie:Script]] | [[Catégorie:Script]] | ||
Version du 30 août 2013 à 10:35
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