OpenStackで作成したサーバの情報を保存しようと思い、次のようなスクリプトを作成しました。
SSH_CONFIG=`cat <<EOS
Host $NAME
Hostname $IP
User root
IdentityFile ~/.ssh/id_rsa
EOS`
echo $SSH_CONFIG >> ~/.ssh/config
しかし、保存したら改行がうまく反映されず、一行になって出力されていました。
Host web-server1 Hostname xxx.xxx.xxx.xxx User root IdentityFile ~/.ssh/id_rsa StrictHostKeyChecking no UserKnownHostsFile /dev/null
変数を””で囲うことによって、反映されるようになります。
echo "$SSH_CONFIG" >> ~/.ssh/config
Host web-server1
Hostname xxx.xxx.xxx.xxx
User root
IdentityFile ~/.ssh/id_rsa
StrictHostKeyChecking no
UserKnownHostsFile /dev/null