What I love about Linux and FreeBSD is the ability to quickly and beautifully automate routine actions. For example, the typical task of any sysadmin is to prescribe the virtual host konfig for Apache. Automate this action will help here such a script:
As usual, the script starts with #! / Bin / sh, but more ...
The first two lines are “fool protection”, which requires that you enter two arguments - the host name (domain) and its IP
The next four lines are the variables in which we indicate where the directory of the connected configs lies, the basic location of the home directory and the user name. Note that on the fourth line, the VHOST variable is generated based on the previous variables and the first argument.
Two lines create a directory for content and assign owner rights.
But more cunning. The cat command will read everything until it encounters the EOF combination and writes all the resulting ones into a file. Since the reading is actually from the body of the script, we simply write the config template directly in it, and during processing all variables are replaced with values ​​and recorded as a ready-made config.
The last line causes Apache to re-read configs.
That's all. True shell scripting is elegant and beautiful?