Solved

Debian MySQL Bash Script Auto-Installer

Posted on 2010-11-15
6
899 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now