I just wanted to execute this bash command in expect script:
mysql -u root -h localhost -proot dbTest < temp.sql
I added spawn
to the beginning but it is not working. I think "<" symbol means nothing in expect!
Can anyone help me to solve this issue?
People tend to use sqldump and mysqldump. I like the quote in the below link saying rubbish
with phpmyadmin:
how to import a very large query over phpmyadmin?
Concerning cron
or expect
...
I know cron has trouble say with dates and often what works at a command line has to be shoved in a bash script for easier work. Then cron runs the .sh script versus embedded string.
Also it is a duplicate question of yours from 2 hours ago.
spawn
does not support the <
direction but you can do like this:
spawn sh -c "mysql -u root -h localhost -proot dbTest < temp.sql"
Seems like you want to run mysql
in the non-interactive way so you can also use Expect
's system
command:
system "mysql -u root -h localhost -proot dbTest < temp.sql"
or Tcl
's exec
command:
exec mysql -u root -h localhost -proot dbTest < temp.sql >@ stdout 2>@ stderr
You may need to put the whole system
or exec
command in a catch
block in case the mysql
fails:
catch {system "mysql ..."} catched
# or
catch {exec mysql ...} catched
I have now found a solution for this problem. I avoided the "<" symbol, so we can use this command instead:
spawn mysql -u root -h localhost -proot dbTest -Bse "source temp.sql"