Plz help me using expect script for remote host

I am newbie in Unix and Expect script, so please help me :frowning:
I'm using expect script for remote another host:

#!/usr/bin/expect -f

set timeout 10
spawn ssh -l root 10.120.18.4
expect "password:"
send "password\r"
expect "@"
interact

And now how can i use expect script for access mysql on 18.4 and insert data?
I used script below:

set timeout 10
spawn ssh -l root 10.120.18.4
expect "password:"
send "password\r"
expect "@"
interact
spawn mysql -uroot -pPassword DatabaseName
expect "mysql>"
return

However the result is only access host 18.4 and doesn't show mysql.

Please help me!

  1. Please use [CODE] tags when posting script listings
  2. Choose a meaningful subject next time. Crying out "Please help me" isn't really professional
  3. Using expect to avoid entering the password with SSH is a bad idea. Use public keys instead.
  4. In general, search the forums first for a few keywords, it's quite possible that someone else already had the same problem & found a solution
1 Like

Yes i will apply this rule, as your experience in Unix can you provide me the way: using expect script for insert/update database in another host like my background:

Host A contain the web APP for register user, the user information contained by database name USER on host B

Now i am at host A and want using expect script for create user on web App and after that insert/update user on database USER on host B!
I can create the user on web App on host A with expect script but i don't know the way for using expect script: insert and update user on database USER on host B!

Thanks!