Linux for SSH command plus auto-complete function

Source: Internet
Author: User

So I returned to the use of Linux command line terminals, by creating multiple alias to meet the different SSH parameters, such as some need to use key, some need to use a password, and then add all the servers to a text file in a list of the way to update, It also feels good to use the content as a list of these alias's automatic completion.

Specific configuration:
Define Alias

The code is as follows Copy Code

[Dong.guo@heydevops ~]$ vim. BASHRC

Alias sshads= ' ssh-t-i/home/dong.guo/workspace/sshkeys/key_adsymp-l adsymp '
Alias sshrootdraw= ' sshpass-p ' drawbridge ' ssh-l root '
Alias sshrootkey= ' ssh-t-i/home/dong.guo/workspace/sshkeys/key_root-l root '
Create the server list file and enter all server host names
[Dong.guo@heydevops ~]$ head-n 10/home/dong.guo/workspace/autocomp/servers.list


api1e
api2e
api3e
c1e
c2e
c3e
c4e
c5e
cb1e
cb2e

Add the AutoComplete feature to the created alias Www.111cn.net

The code is as follows Copy Code

[Dong.guo@heydevops ~]$ vim. BASHRC

# Enable Auto-completion of servers via Sshads, Sshrootdraw and Sshrootkey
function _servers () {
Compreply= ()
Local Cur=${comp_words[comp_cword]};
Local Com=${comp_words[comp_cword-1]};
Case $com in
' Sshads ')
Local servers= ($ (cat/home/dong.guo/workspace/autocomp/servers.list))
Compreply= ($ (compgen-w ' ${servers[@]} '--$cur))
;;
' Sshrootdraw ')
Local servers= ($ (cat/home/dong.guo/workspace/autocomp/servers.list))
Compreply= ($ (compgen-w ' ${servers[@]} '--$cur))
;;
' Sshrootkey ')
Local servers= ($ (cat/home/dong.guo/workspace/autocomp/servers.list))
Compreply= ($ (compgen-w ' ${servers[@]} '--$cur))
;;
Esac
}

Complete-f _servers Sshads
Complete-f _servers Sshrootdraw
Complete-f _servers Sshrootkey
Make configuration effective
[Dong.guo@heydevops ~]$ Source BASHRC

Gracefully tap the TAB key to experience the thrill of automatic completion,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.