Created
October 24, 2017 16:09
-
-
Save Ameausoone/52b8266b953771778b3f3b711d1059d0 to your computer and use it in GitHub Desktop.
Script à ajouter dans .bashrc qui permet de se connecter sur une série de machines, directement en shell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copy list of servers in ~/.servers | |
function refresh_server_list | |
{ | |
for ip in $(seq 1 254) ; do nslookup 10.1.2.$ip | grep 'name =' | cut -d ' ' -f 3 | cut -d . -f 1 >> ~/.servers_tmp ; done | |
mv ~/.servers_tmp ~/.servers | |
} | |
(refresh_server_list) | |
if [ -f ~/.servers ] ; then | |
for hostname in $(cat ~/.servers) ; do | |
if [[ $hostname != *-* ]] | |
then | |
# Replace . by _ because string with "." are not exportable | |
hostnameExportable=$(tr '.' '_' <<< $hostname ) | |
# Add hostname to environnement variable | |
export $hostnameExportable="$hostname" | |
# Add alias to connect to servers with server name | |
alias $hostnameExportable="ssh user@\${$hostnameExportable}" | |
fi | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment