Pfsense Host listing to bash auto-complete

Setup a daily cron tab as root (sudo crontab -e) to login to pfsense and grab your listing of hosts.

@daily /usr/bin/scp /dev/stdout | grep ^10. | awk ‘{print $2}’ | tr A-Z a-z > /data/network_devices.txt

Next lets edit our personal bashrc file to perform host name auto-completing using the list of host names in the file:

vi .bashrc

Add the following at the bottom of the file:

#Perform auto-complete for the following commands:
complete -W “$(cat /data/network_devices.txt;)” telnet
complete -W “$(cat /data/network_devices.txt;)” ssh
complete -W “$(cat /data/network_devices.txt;)” ping
complete -W “$(cat /data/network_devices.txt;)” traceroute
complete -W “$(cat /data/network_devices.txt;)” dig
complete -W “$(cat /data/network_devices.txt;)” scp

#Optional – create an alias to update all your screen sessions:
alias update-screen=”screen -X at # stuff \”source ~/.bashrc\n\””

Lastly, change to root, generate ssh keys if you don’t already have them created, copy the keys up to your pfsense firewall

sudo -s -H -u root

Reload your personal bashrc file and you are all set:
source ~/.bashrc

Leave a Reply

Your email address will not be published. Required fields are marked *