Wikipedia:Reference desk/Archives/Computing/2023 June 26

From Wikipedia, the free encyclopedia
Computing desk
< June 25 << May | June | Jul >> June 27 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


June 26[edit]

Apache virtual host creation automation[edit]

This is my current approach, in Bash language, to create Apache virtual host files:

#!/bin/bash

### Make some read operations verified ###

function read_and_verify  {
    read -p "$1:" tmp1
    read -p "$2:" tmp2
    if [ "$tmp1" != "$tmp2" ]; then
        echo "Values unmatched. Please try again."; return 2
    else
        read "$1" <<< "$tmp1"
    fi
}

### read and verify for crucial information about your website ###

read_and_verify domain "Please enter the domain of your web application twice" 
read_and_verify dbrootp "Please enter the app DB root password twice" 
read_and_verify dbuserp "Please enter the app DB user password twice"

### Creaate a virtual host file ###

cat <<-EOF > /etc/apache2/sites-available/$domain.conf
    <VirtualHost *:80>
        ServerAdmin admin@"$domain"
        ServerName ${domain}
        ServerAlias www.${domain}
        DocumentRoot $web_application_root/${domain}
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
EOF

### Make a softlink from the virtual host file, to the file enabling the virtual host ###

ln -sf /etc/apache2/sites-available/"$domain".conf /etc/apache2/sites-enabled/

The only programming languages I have elementary knowledge with are Bash and JavaScript.

Would you do it othewise? With another shell?

Would you install COBOL or Python or Node.JS or anything else (or just use PERL) to build the script with?

Thanks. 2A10:8012:11:A87A:646D:9BA4:51C7:BE1F (talk) 19:24, 26 June 2023 (UTC)[reply]

There is no reason to NOT use a Bash script. It is becoming common in Linux for the new kids to prefer Python to the point that many don't even comprehend Bash. But, look at it this way - you are running a Bash interpretter. So, if you run a shell script, everything is loaded and running. If you use Python, you have to load the Python interpretter. Then, what if your script works in Python 2 and you have Python 3 loaded? Conflict. When it comes down to it, you could write your script in any language, but if you know Bash, why not stick with it because you are essentially just executing Bash commands even if you execute them from Python or COBOL or PHP or C++ or ADA or ... 12.116.29.106 (talk) 13:22, 27 June 2023 (UTC)[reply]
If the same commands would be inside a traditional programming language document then yea, I'll just stick to Bash I guess. I do wonder if using another shell like ksh or zsh would end in a more "COBOL-like" wordy-humany syntax... I just never worked with ksh or zsh. Primarily just curiosity. 2A10:8012:11:A87A:29BB:E6CF:D96F:37DC (talk) 13:49, 27 June 2023 (UTC)[reply]
There are importand differences between compiled and interpreted languages, and some that are a half-way case. See Interpreter (computing)#Compilers versus interpreters for a fuller description. Of the languages you mention COBOL, C++ and ADA are all compiled and will generally run an order of magnitude of more faster. Martin of Sheffield (talk) 13:48, 27 June 2023 (UTC)[reply]