Solved

Debian MySQL Bash Script Auto-Installer

Posted on 2010-11-15
6
915 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

730 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