Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Asked
Viewed 43 times
3
\$\begingroup\$

I've written the following Bash script used to duplicate a webapp/website you have (say, a Wordpress website) locally on your server environment, for testing purposes, indicating after 2 days if you have yet to delete it after you've finished your testing.

Here's the code:

cat <<-'DWA' > /opt/dwa.sh
    #!/bin/bash
    DWA() {
        tiesto='tiesto'
        read domain
        find /var/www/html ${domain} -exec cp ${domain} ${tiesto} {} \;
        sed -i 's/${domain}/${tiesto}'/g /var/www/html/tiesto/wp-config
        sed -i 's/${domain}/${tiesto}'/g /var/www/html/tiesto/wp-config
        mysql -u root -p << MYSQL
            create user '${tiesto}'@'localhost' identified by '${psw}';
            create database ${tiesto};
            GRANT ALL PRIVILEGES ON ${tiesto}.* TO ${tiesto}@localhost;
        MYSQL
        sleep 2d
        echo "If you haven't already, eliminate tiesto (dir & db)."
        tmux kill-session
    }
    DWA
DWA
chmod +x /opt/dwa.sh && cat >> /etc/bash.bashrc <<< "alias dwa='tmux new-session -d bash /opt/dwa.sh'"

After a reboot (due to the added alias), run it by the alias + an argument to indicate the app you're working on.

For example, if you named the app/site as example.com (I assume you named the site's dir, the DB user, and the DB instance the same), execute this in Bash:

dwa example.com

The webapp/site should be duplicated.

I would appreciate your review.

\$\endgroup\$
1
  • \$\begingroup\$ Contribute to the github project here, if you wish. \$\endgroup\$
    Arcticooling
    –  Arcticooling
    2017-11-30 08:55:21 +00:00
    Commented Nov 30, 2017 at 8:55

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.