Making an alias for SSH MySQL login using ENDSSH heredoc

I want to make an alias that is kept in my bashrc file to log into a remote MySQL db via SSH. Assume that I can't add/alter any files on the remote machine that I'm SSHing into. Here's the relevant code.

function ssh_mysql {
  echo "SSHing to $server"
  ssh -t -t $suser@$server <<ENDSSH
    eval "mysql -h "$host" -u $user -p $pass $db"
alias wt_mysql=ssh_mysql

The Problem: Entering 'wt_mysql' into the terminal as an alias SSHs and logs into MySQL fine.. but when trying to enter any command/query/etc at the MySQL prompt, none of what I've submitted is executed/run. Including the 'exit' command. I have to ctrl C to get back to my local terminal. although its a bit out of my understanding I believe the problem is related to this topic, Terminating SSH session executed by bash script How can I make sure that mysql and any subsequent commands are executed remotely? Thanks!


I don't understand why you're using eval (or why you're passing the -t switch twice).

I would expect this ssh command to do what you want:

ssh -t $suser@$server "mysql -h '$host' -u $user -p $pass $db"

Need Your Help

How to get information about size from http response urllib in python

python python-2.7 urllib2 httpresponse urllib

Basically i have few urls in a list of some video file and i want to find size of those videos without downloading them using urllib.

All pixels except one pixel in matlab

matlab matrix matrix-indexing

Say that we have a 3x3 matrix in matlab. If we type x(:), this will select all the elements in the matrix, right?