?
Solved

Debian MySQL Bash Script Auto-Installer

Posted on 2010-11-15
6
Medium Priority
?
940 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
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 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