Skip to content

Instantly share code, notes, and snippets.

@kitaro-tn kitaro-tn/ssh socket.md
Last active Jul 18, 2018

Embed
What would you like to do?
ssh control socket port foward

SSHでcontrol socketを利用したport foward

  • mysql hostをport foward
ssh -M -S ctl_path -Nf -L 33306:db-instance:3306 ec2-user@10.0.0.0 -i ~/.ssh/aws.pem
  • control socketをチェック
ssh -S ctl_path -O check ec2-user@10.0.0.0
  • control socketを終了
ssh -S ctl_path -O exit ec2-user@10.0.0.0

おまけ: mysqlの結果を配列で受け取る

result=$(mysql -u user -h 127.0.0.1 -P 33306 -ppass dbname -N -se "SELECT id, name FROM member LIMIT 1")
IFS=$'\t' read -ra columns <<< result
echo "id: ${columns[0]}"
echo "name: ${columns[1]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.