Part 2The system administrator is a lazy person. Usually he tries to do the maximum work, putting a minimum of effort, and this often requires automating many routine procedures. For example, a set of full host names when creating an ssh connection, or the long arguments of some commands :)
Today I will try to tell you about using shell functionality like bash completion.
So, almost any shell by default can add paths to files and directories:
')
root@mould:~# mkdir very_long_dir_name
root@mould:~# cd ve[Tab]
root@mould:~# cd very_long_dir_name/
bash (in my case) after pressing the Tab key will add the name of the director's office (if it can be determined uniquely by the first characters typed), or will show the options:
root@mould:~# ls .s[Tab]
.ssh/ .subversion/
But at the same time, some shells can complement not only the paths, but also the arguments for a number of commands. For example:
root@mould:~# apt-get up[Tab]
update upgrade
Or even more complex structures:
root@mould:~# apt-get install bash-[Tab]
bash-builtins bash-completion bash-doc bash-minimal bash-static
For this functionality in debain-based distributions (I can't say anything about the rest) the contents of the bash-completion package are responsible.
In order to activate the completion capabilities, it’s enough to do the following:
root@mould:~# . /etc/bash_completion
Or add such a call to your .bashrc file, then re-login:
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
Most likely you have already written this, but commented out.
Let's try to start using one of the most frequently required companies - the addition of host names when accessing them via ssh.
To get started, you will need to turn off host name hashing in ~ / .ssh / known_hosts. With the “boxed” settings, the line in this file looks like this:
|1|yVV33HmBny6RPYWkUB5aW+TksqQ=|f11ZL/FI9/Krfw2bqN0tBJeeq4w= ssh-rsa AAAAB3Nz__--__2bYw==
,
that does not suit us.
After setting the
HashKnownHosts No value in the ssh client config file (/ etc / ssh / ssh_config or ~ / .ssh / config), and clearing the .ssh / known_hosts (otherwise the correct lines for new hosts will be added to it) we will get a readable after the first attempt to write to known_hosts login to the host:
mould,11.22.33.44 ssh-rsa AAAAB3NzaC1y__--__c2EAANq6/Ww==
.
And this, in turn, will allow the use of komplishn names when installing an ssh connection:
veshij@dhcp250-203:~ $ ssh mould[Tab]
mould mould01e
If in your "submission" more than 5-10 cars it will be very convenient.
And, by the way, the add-on will work not only for ssh, but also for a number of other programs: ping, traceroute, telnet, etc. And not only by the hostname, but also by the ip-address.
If this topic turns out to be interesting, in the next section I can tell you how to customize the addition of commands and arguments for your own scripts. For example:
root@mould:~# my_test_script --[Tab]
--help --kill-all-humans --conquer-the-world