I have the following bash script which wraps an expect script (in here-document form):
#!/bin/bash
PASSWORD_MYSQL_ROOT=root
expect <<- DONE
set timeout -1
spawn mysqldump --all-databases --user=root --password --protocol=TCP --host=localhost --verbose > somebackupfile.sql
expect "*?asswor?:*"
send -- "$PASSWORD_MYSQL_ROOT\r"
expect eof
DONE
When I execute this script, I get the following output:
spawn mysqldump --all-databases --user=root --password --protocol=TCP --host=localhost --verbose > somebackupfile.sql
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
send: spawn id exp4 not open
while executing
"send -- "root\r""
So something didn't work right.
After some try and error, I found out that the stdout stream redirect > somebackupfile.sql
is the culprit -- the script works once this redirect is removed.
So I am wondering: How do I use stream redirection in expect scripts?