Skip to content

Instantly share code, notes, and snippets.

@penguin2716

penguin2716/ssh

Created Feb 6, 2015
Embed
What would you like to do?
~/.ssh/conf.d の中の設定ファイルを結合してからsshを叩くシェルスクリプト
#!/bin/bash
#
# ssh (concatenating split config file)
#
# Copyright (c) 2014 Takuma Nakajima
#
# This software is released under the MIT License.
# http://opensource.org/licenses/mit-license.php
#
CONFIG_ON_MEMORY=/dev/shm/$USER-ssh-config
CONFIG_PATH=$HOME/.ssh/config
CONFIG_DIR=$HOME/.ssh/conf.d
which ssh >/dev/null 2>&1
# check if ssh exists
if [ $? -ne 0 ]; then
echo "ssh does not exists or is not in \$PATH."
exit 1
fi
# create ~/.ssh/config as a symlink to /dev/shm/ssh-config
if [ ! -e $CONFIG_PATH ]; then
echo 'creating symlink'
ln -s $CONFIG_ON_MEMORY $CONFIG_PATH
fi
# exit if ~/.ssh/config is not a symlink
if [ ! -L $CONFIG_PATH ]; then
echo "ERROR: $CONFIG_PATH is not a symbolic link."
exit 1
fi
# delete and regenerate config on memory
rm -rf $CONFIG_ON_MEMORY
touch $CONFIG_ON_MEMORY
chmod 600 $CONFIG_ON_MEMORY
for config in `find $CONFIG_DIR -type f`; do
cat $config >> $CONFIG_ON_MEMORY
echo >> $CONFIG_ON_MEMORY
echo >> $CONFIG_ON_MEMORY
done
# generate ssh command
SSH_COMMAND="/usr/bin/ssh -F $CONFIG_ON_MEMORY"
while [ -n "$1" ]; do
SSH_COMMAND="$SSH_COMMAND \"$1\""
shift
done
# spawn the command
eval $SSH_COMMAND
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.