LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-15-2012, 06:22 AM   #1
eyanu
Member
 
Registered: Jul 2012
Location: kampala,Uganda
Distribution: backtrack
Posts: 87

Rep: Reputation: Disabled
BUG in Bash script to automate VPS installation


Hello am writing a script that would automate a VPS installation however am getting some errors, and i need your help.
here is part of the script:
Quote:
#-------------------------------------------------------------------------------
# We first configure the HOSTNAME
#-------------------------------------------------------------------------------
read -p "Please enter your HOSTNAME (e.g. puck384): " HOSTNAME
check=`echo $HOSTNAME | grep -E "[^[:alnum:]\-]"`
if [[ "$check" != "" ]]
then
echo "$HOSTNAME is not a valid HOSTNAME"
exit 2
fi

read -p "Please enter the server domain name ($HOSTNAME.<domainname>): " FQDNNAME
check=`echo $FQDNNAME | grep -E "[^[:alnum:]\-\.-]"`
if [[ "$check" != "" ]]
then
echo "$FQDNNAME is not a valid domain name!"
exit 2
fi
# We now combine the HOSTNAME to the domain name
FQDNNAME="$HOSTNAME.$FQDNNAME"

read -p "Enter the First nameserver's IP address" nameserver1
if [[ $nameserver1 =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
then
$nameserver1
else
echo "Sorry that is not a valid IP address"

read -p "Enter the Second nameserver's IP address" nameserver2
if [[ $nameserver2 =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
then
$nameserver2
else
echo "Sorry that is not a valid IP address"

## --here wait and first investigate how to do that
echo "Enter Diskpace in Gigabites starting with minimumn allowed space:"min
echo "Enter Diskpace in Gigabites the maximum allowed" max

## -- VPS IP address
read -p "Enter IP address for you new VPS:" IP
if [[ $IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
then
$IP
else
echo "Sorry that is not a valid IP address"

cd /var/lib/vz/template/cache
arch=`uname -m`
if [[ "$arch" == 'x86_64']]
then
wget http://download.openvz.org/template/...minimal.tar.gz
architecture=debian-6.0-amd64-minimal
else
wget http://download.openvz.org/template/...minimal.tar.gz
architecture=debian-6.0-i386-minimal
fi
vzctl create 104 --ostemplate $architecture
vzctl set 104 --onboot yes --save
vzctl set 104 --nameserver $nameserver1 --save
vzctl set 104 --nameserver $nameserver2 --save
vzctl set 104 --hostname $FQDNNAME --save
vzctl set 104 --diskspace ${min}G:${max}G --save
vzctl set 104 --ipadd 69.64.37.212 --save
vzctl set 104 --ram 10.5G --swap 5G --save
vzctl start 104
vzctl exec 104 passwd
However when i run it i get:
Quote:
+ read -p 'Enter the First nameserver\'\''s IP address: ' nameserver_one
Enter the First nameserver\'s IP address: xx.xx.xx.xx
vps.sh: line 48: syntax error in conditional expression
vps.sh: line 49: syntax error near `then'
vps.sh: line 49: `then
Is there something am doing wrong, would really appreciate it if you pointed it out.
 
Old 11-15-2012, 06:58 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
You are missing ";" after if [[test]], so once try with this:
Code:
if [[ "$arch" -eq "x86_64"]];
 then
 wget http://download.openvz.org/template/...minimal.tar.gz
 architecture=debian-6.0-amd64-minimal
 else
......
.......
 
Old 11-15-2012, 07:54 AM   #3
eyanu
Member
 
Registered: Jul 2012
Location: kampala,Uganda
Distribution: backtrack
Posts: 87

Original Poster
Rep: Reputation: Disabled
Hey shivaa, thanks alot i just made it used if
Quote:
[[ "$arch" == "x86_64" ]]
notice the space after the double quote after the 64" ]
It's now up and running, thanks again.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how i can make script bash or perl to create vps ? a_1 Linux - Server 5 11-15-2012 07:34 AM
Create a bash script to automate installation of a program ASTRAPI Linux - Newbie 7 05-13-2012 06:55 AM
[SOLVED] Bash script to Automate the Virtual Host creation process!! anishkumarv Linux - Newbie 3 03-14-2011 10:03 PM
how to automate an installation script suppressing user interaction aditi Programming 2 02-08-2010 11:43 PM
Automate Samba logon with a bash script? achtung_linux Linux - Networking 6 10-22-2006 02:36 AM


All times are GMT -5. The time now is 04:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration