Solved

Debian MySQL Bash Script Auto-Installer

Posted on 2010-11-15
6
892 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:vePortal
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

771 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

16 Experts available now in Live!

Get 1:1 Help Now