2

I have the following file: exp.exp

#!/usr/bin/expect

db_host='localhost'
db_name='webui_dev'
db_user='root'
db_pass='rootpass'
new_db_name='db_2011'

expect <<EOF
  log_user 0
  spawn mysql -h $db_host -u $db_user -p $db_pass 'create database $new_db_name'
  expect "password:"
  send "$db_pass\r"
  log_user 1
  expect eof
EOF

I make it executable by sudo chmod +x script/year_changer/create_db.exp, but if I try to execute it I get an error:

couldn't execute "mysql": no such file or directory
    while executing
"spawn mysql -h localhost  -u root -p rootpass  'create database db_2011'"

2 Answers2

3

Giving a command, without a full path, only really works without a path to the executable if its in your path variables - as per the mysql docs, you need to add PATH=${PATH}:/usr/local/mysql/bin to your path - in .bashrc for interactive shells or .bash_profiles for non interactive ones.

Journeyman Geek
  • 133,878
1

Make sure your mysql binary is in your $PATH variable. You can check this by executing

echo $PATH;

If you do not see the path to your mysql binary there, you'll have to modify the PATH variable and add the path to your mysql binary in the ~/.bash_profile or ~/.bash_rc file to make it available globally on login

You can alternatively use the full path to your mysql binary in your code. For example

spawn /usr/bin/mysql -h $db_host -u $db_user -p $db_pass 'create database $new_db_name'