2006-02-12 21:14:21 +08:00
|
|
|
|
|
|
|
function __fish_print_hostnames -d "Print a list of known hostnames"
|
|
|
|
|
|
|
|
# Print all hosts from /etc/hosts
|
2012-11-27 11:47:35 +08:00
|
|
|
if test -x /usr/bin/getent
|
|
|
|
getent hosts | tr -s ' ' ' ' | cut -d ' ' -f 2- | tr ' ' '\n'
|
2013-02-15 08:41:49 +08:00
|
|
|
else if test -r /etc/hosts
|
2012-11-27 13:02:13 +08:00
|
|
|
tr -s ' \t' ' ' < /etc/hosts | sed 's/ *#.*//' | cut -s -d ' ' -f 2- | sgrep -o '[^ ]*'
|
2006-02-12 21:14:21 +08:00
|
|
|
end
|
|
|
|
# Print nfs servers from /etc/fstab
|
2013-02-15 08:41:49 +08:00
|
|
|
if test -r /etc/fstab
|
2006-11-29 22:00:04 +08:00
|
|
|
sgrep </etc/fstab "^\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\|[a-zA-Z.]*\):"|cut -d : -f 1
|
2006-02-12 21:14:21 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# Print hosts with known ssh keys
|
2013-04-02 05:42:40 +08:00
|
|
|
cat ~/.ssh/known_hosts{,2} ^/dev/null | grep -v '^|' | cut -d ' ' -f 1| cut -d , -f 1
|
2009-02-03 05:02:42 +08:00
|
|
|
|
|
|
|
# Print hosts from ssh configuration file
|
|
|
|
if [ -e ~/.ssh/config ]
|
2013-04-02 04:32:11 +08:00
|
|
|
sgrep -i '^ *host' ~/.ssh/config | grep -v '[*?]' | cut -d ' ' -f 2
|
2009-02-03 05:02:42 +08:00
|
|
|
end
|
2006-02-12 21:14:21 +08:00
|
|
|
end
|
|
|
|
|