[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Debian MySQL Bash Script Auto-Installer

Posted on 2010-11-15
6
Medium Priority
?
937 Views
Last Modified: 2012-05-10
Hi all,
I am attempting to use a bash script to install mysql on a debian/ubuntu VPS from the node side, During the install you are given a few options for which ive tried to use "EXPECT" to over-ride.

Here are my scripts

installsql.sh...
        cd /exapps
        echo "=============== APT-UPDATE =================="
        ./apt-update.exp "$VEID" "N"
        /usr/sbin/vzctl exec $VEID apt-get -q -y upgrade

        cd /exapps
        echo "=============== SQL INSTALL ==================="
        ./sqlinstall.exp "$VEID" "$SQLPASS"

The first one (apt-update.exp)
is this code:
#!/usr/bin/expect --
#
#
spawn /usr/sbin/vzctl exec [lindex $argv 0] apt-get update
expect ?
send [lindex $argv 1]\r
wait
exit 0

And this code simply answers "N" to a prompt to update a vendor distribution file update.

Then my final file, "sqlinstall.exp" performs the install expecting :  for root passwords in both mysql-server and mysql-server5.1 installers.

#!/usr/bin/expect --
#
#
spawn /usr/sbin/vzctl exec [lindex $argv 0] apt-get install -y mysql-server*
expect :
send [lindex $argv 1]\r
expect :
send [lindex $argv 1]\r
expect :
send [lindex $argv 1]\r
expect :
send [lindex $argv 1]\r
wait
exit 0



My problem is when running the script i am getting this error:

=============== APT-UPDATE ==================
spawn /usr/sbin/vzctl exec 103 apt-get update
send: spawn id exp5 not open
    while executing
"send [lindex $argv 1]\r"
    (file "./apt-update.exp" line 7)
=============== SQL INSTALL ===================
spawn /usr/sbin/vzctl exec 103 apt-get install -y mysql-server*
send: spawn id exp5 not open
    while executing
"send [lindex $argv 1]\r"
    (file "./sqlinstall.exp" line 6)


And ive checked and double checked 100% all of the areguments are working as they should!
Please help me here its driving me insane!
0
Comment
Question by:vePortal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 7

Expert Comment

by:Hatrix76
ID: 34136525
Hi, a better way would be to preseed the answers to the debconf configuration database, then the installation goes on without any questions asked.

Read here about preseeding (for installations and later on package installations with debconf-(get|set)-selections:
https://help.ubuntu.com/8.04/installation-guide/i386/preseed-contents.html
https://help.ubuntu.com/8.04/installation-guide/i386/preseed-creating.html

The documentation is for ubuntu but applies as well to debian, you can find this documentation surely on the debian documentation sites as well.

best regards

Ray
0
 

Author Comment

by:vePortal
ID: 34136542
Hi Ray,
I considered this already however my commands need to be passed via /vzctl as this is operated from the NODE to the VPS

And in doing so using debconf doesn't work, ot at least in none of my attempts it hasnt worked.
0
 
LVL 7

Expert Comment

by:Hatrix76
ID: 34136791
hmm, just a thought, can't you do it via SSH?


but what you should be able to do is the following:

cat debconf-answerfile-mysql.cnf | sudo vzctl exec 1136 "cat - > /tmp/debconffile"
sudo vzctl exec 1136 "debconf-set-selections < /tmp/debconffile"


I just tested it with cat'ing text inside a file and put out a the content inside a VPS with those commands and it works, so you should be able to transfer the preseed answer into the vps and set them to debconf, what I tested was:


echo "lalala" > /tmp/testfile
cat /tmp/testfile | sudo vzctl exec 1136 "cat - > /tmp/testfileVPS"
sudo vzctl exec 1136 "cat < /tmp/testfileVPS"
lalala

Or are there other problems preventing you from using io-redirection?

I think the expect will not work because I am not sure if vzctl creates the necessary stdio environment for expect, but I can be terribly wrong on this one.

best
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vePortal
ID: 34136815
I dont think the client will be happy with using a "Low Jack" method such as logging in via SSH and performing the install using expect.
0
 
LVL 7

Expert Comment

by:Hatrix76
ID: 34136816
ah, and then there is       --trivial-only  parameter for apt-get, in the man page it says it is related to -y, but will answer no, so this could be the answer for your first expect script.

best
0
 
LVL 7

Accepted Solution

by:
Hatrix76 earned 2000 total points
ID: 34136834
I hope you realized that my post about the io-redirection is not regarding ssh! it uses vzctl exec exclusivly. i just asked in the first sentence if ssh could be an alternative!
best
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question