📜 ⬆️ ⬇️

Bash scripting is easy

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:
 #!/bin/sh [ -z $1 ] && (echo "Enter hostname"; exit 1) [ -z $2 ] && (echo "Enter IP"; exit 1) HTTPD=/etc/httpd/conf.d BASE=/home USER=www VHOST="$BASE/$USER/$1/htdocs" mkdir -p $VHOST chown -R $USER:$USER $BASE/$USER/$1 cat << EOF > $HTTPD/$1.conf <VirtualHost $2:80> ServerName $1 ServerAlias www.$1 DocumentRoot $VHOST ErrorLog /var/log/httpd/$1.error_log CustomLog /var/log/httpd/$1.log combined </VirtualHost> EOF service httpd reload 


As usual, the script starts with #! / Bin / sh, but more ...


That's all. True shell scripting is elegant and beautiful?

')

Source: https://habr.com/ru/post/78257/


All Articles