I'm working on a db server but I must ssh many times to access to it. Something like this:
step1) ssh [email protected]
pw: xxx
step2) ssh [email protected]
pw:yyy
step3) sudo mysqlsh
pw:zzzz
step4) mysql -u root -paaaa
use mydb;
How to run these commands in a sequence? I want to create a script batch to do it. How to do it?
Update: Itried to do this but doesn't work. It just log in the first time.
#!/usr/local/bin/expect
spawn ssh xxx@xxx
expect "*password:"
send "xxx\r";
interact
expect "*$ "
spawn ssh yyy@yyy
expect "*password:"
send "yyy\r";
interact