2006-02-12 13:14:21 +00:00
|
|
|
|
|
|
|
function __fish_print_hostnames -d "Print a list of known hostnames"
|
|
|
|
|
|
|
|
# Print all hosts from /etc/hosts
|
2012-11-27 03:47:35 +00:00
|
|
|
if test -x /usr/bin/getent
|
|
|
|
getent hosts | tr -s ' ' ' ' | cut -d ' ' -f 2- | tr ' ' '\n'
|
2013-04-04 01:46:50 +00:00
|
|
|
else if test -r /etc/hosts
|
2012-11-27 05:02:13 +00:00
|
|
|
tr -s ' \t' ' ' < /etc/hosts | sed 's/ *#.*//' | cut -s -d ' ' -f 2- | sgrep -o '[^ ]*'
|
2006-02-12 13:14:21 +00:00
|
|
|
end
|
|
|
|
# Print nfs servers from /etc/fstab
|
2013-04-04 01:46:50 +00:00
|
|
|
if test -r /etc/fstab
|
2006-11-29 14:00:04 +00:00
|
|
|
sgrep </etc/fstab "^\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\|[a-zA-Z.]*\):"|cut -d : -f 1
|
2006-02-12 13:14:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Print hosts with known ssh keys
|
2013-09-19 15:18:35 +00:00
|
|
|
# Does not match hostnames with @directives specified
|
|
|
|
sgrep -Eoh '^[^#@|, ]*' ~/.ssh/known_hosts{,2} ^/dev/null
|
2009-02-02 21:02:42 +00:00
|
|
|
|
2014-01-10 19:58:54 +00:00
|
|
|
# Print hosts from system wide ssh configuration file
|
|
|
|
if [ -e /etc/ssh/ssh_config ]
|
|
|
|
# Ignore lines containing wildcards
|
|
|
|
sgrep -Eoi '^ *host[^*]*$' /etc/ssh/ssh_config | cut -d '=' -f 2 | tr ' ' '\n'
|
|
|
|
end
|
|
|
|
|
2009-02-02 21:02:42 +00:00
|
|
|
# Print hosts from ssh configuration file
|
|
|
|
if [ -e ~/.ssh/config ]
|
2013-09-19 15:18:35 +00:00
|
|
|
# Ignore lines containing wildcards
|
|
|
|
sgrep -Eoi '^ *host[^*]*$' ~/.ssh/config | cut -d '=' -f 2 | tr ' ' '\n'
|
2009-02-02 21:02:42 +00:00
|
|
|
end
|
2006-02-12 13:14:21 +00:00
|
|
|
end
|