Learn about Centmin Mod LEMP Stack today
Become a Member

Nginx Automate adding of nginx vhost

Discussion in 'Centmin Mod Insights' started by dorobo, Jun 11, 2014.

Tags:
  1. dorobo

    dorobo Active Member

    420
    104
    43
    Jun 6, 2014
    Ratings:
    +161
    Local Time:
    12:12 PM
    latest
    latest
    Supposed you have many domains and you need to add them one by one by choosing number 2 (add nginx vhost) in the menu.

    Can you automate the pressing of number 2 and domain input using bash?

    Like for example:

    Code:
    #!/bin/sh
    cd /usr/local/src
    ./centmin.sh
    what is the next command to put here to simulate the pressing of number 2
    mydomain1.com <-- what is the next command that will input the domain
    press 2 again
    domain2.com
    press 2 again
    and so on
    
    or the only way is to copy and paste the commands inside nginx_addvhost.inc for each domains in a bash script?
     
  2. dorobo

    dorobo Active Member

    420
    104
    43
    Jun 6, 2014
    Ratings:
    +161
    Local Time:
    12:12 PM
    latest
    latest
    I'm a noob at bash scripting but what do you think of this

    if you have many domains and you want to automate the entering of domains

    could you just get the contents of function funct_nginxaddvhost and do something like

    Code:
    domains='domain1.com domain2.com domain3.com domain4.com'
    declare -a array
    array=(${domains})
    for vhostname in ${array[@]}
    do
    insert contents of nginx_addvhost.inc here starting at line 10
    
     
  3. eva2000

    eva2000 Administrator Staff Member

    30,195
    6,789
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,144
    Local Time:
    2:12 PM
    Nginx 1.13.x
    MariaDB 5.5
    probably a better way, I'll see what I can do about a mass domain Nginx vhost creation function for future versions

    edit saw your 2nd post and yeah that is probably the better way in an array of sorts, not sure it would be your code specifically but along those lines or close if you're just inserting the nginx_addvhost.inc contents minus a prompt for the domain name to enter.