Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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'"
share|improve this question
1  
I have to ask the obvious... Is the mysql client installed? –  Joni Sep 12 '13 at 6:08
    
Yes definitely. sudo /usr/local/mysql/support-files/mysql.server restart Shutting down MySQL .. SUCCESS! Starting MySQL .... SUCCESS! –  Andrey Yasinishyn Sep 12 '13 at 6:11
    
Is the mysql command in your $PATH when you run the script? –  Barmar Sep 12 '13 at 6:12
    
@Barmar. Don't know really. How can I check it?? –  Andrey Yasinishyn Sep 12 '13 at 6:13
1  
What happens if you just type mysql from the shell instead of running the script? –  Barmar Sep 12 '13 at 6:14

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer

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'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.