0

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

2 Answers 2

3

Check out linux command "expect".

Sign up to request clarification or add additional context in comments.

3 Comments

Ditto, I use expect for this.
Can you post the script to do the above 4 steps?
I read it and try hard. Your solution can't shh in sequence for sure because "expect" just do at the first level. After logging in xxx@xxx, it can't ssh continuously.
0

I usually see "expect" as giving up, though I have been known to essentially rewrite expect in python to wrap something I don't have source code to.

I'd suggest: Steps 1&2: Use passwordless, passphraseless DSA keys. Step 3: /etc/sudoers can be modified to make sudo not require a password. Step 4: Looks like you're already there.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.