我的脚本是这样的
test.sh
#!/usr/bin/expect
set password root
spawn mysql -u root -p
expect "password:"
send "$password\r\n"
send "drop database blog_api;\r\n"
send "CREATE DATABASE `blog_api` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;\r\n"
send "exit;\r\n"
expect "Bye"
send "mysql -uroot blog_api < 2017-01-09-12:00:09.sql;\r\n"
expect "Enter password:"
send "$password\r\n"
interact
导出是没有问题的,但是导入的话没有效果,大神求教。。。
The value of the variable password has been set in your script. Why not use the shell directly? Execute the command directly
mysql -uroot -p $password blog_api < 2017-01-09-12:00:09.sql
or write it as a shell script and import it.Why do you have to use
expect
? This command naming can be written directly in shellexpect
呢,这个命令命名可以直接用shell来写的如果非要用
If you must useexpect
expect
, try the following🎜 rrreee