LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 03-30-2013, 04:23 PM   #1
juniorb0y007
LQ Newbie
 
Registered: Mar 2013
Posts: 8

Rep: Reputation: Disabled
Bash Script


Hello,

I am taking a Linux class right now, and my teacher has requested me to write a bash script. I have been given IP address of the server to create virtual machine on the server. I need someone to help me with this project by getting me started on this project. I have no clue right now how to start this project. Any help will be appreciated. Here is the requirement:

Write a bash script to create a virtual machine running Scientific Linux 6.3, x86_64 architecture. The
image should include the
telnet client
package, the
ftp
package, and the
httpd
package. The virtual
image should use 1GB of RAM, one virtual CPU, use a 4GB qcow2 disk image, connect to the
“virtual_bridge” network bridge using a random MAC address and DHCP boot protocol. The image
name should be <user name>. The image should run on an IBM blade server with a Scientific
Linux host operating system and KVM hypervisor.
You instructor will provide connection credentials in class.
The script must contain:

a title block

conditional debugging output

variables

ample comments

use of positional parameters to enable debugging and the image




#!/bin/bash

GUESTIMAGESTORAGE=/home/wahab/Desktop/linux

GUESTIMAGEFORMAT=qcow2

ISOSTORAGE=/home/wahab/Desktop/iso

ISOFILENAME=SL-63-x86_64-2012-08-02-Install-DVD.iso

NETWORKBRIDGE=guest_os_bridge

KICKSTARTFILEPATH=/home/wahab/Desktop/kickstart

GUESTRAM=1024
GUESTDISKSIZE=4

REPO64=http://ftp1.scientificlinux.org/linux/scientific/6.3/x86_64/os
GUESTNAME64=sl63x86_64_base

KICKSTARTFILENAME64=sl63x86_64_ks_base.cfg

KICKSTARTFILELOCATION64=$KICKSTARTFILEPATH/$KICKSTARTFILENAME64

echo "$KICKSTARTFILELOCATION64"

# Create images directory

mkdir -p /home/wahab/Desktop/iso

mkdir -p /home/wahab/Desktop/kickstart

mkdir -p $GUESTIMAGESTORAGE

cp /root/install/$KICKSTARTFILENAME64 $KICKSTARTFILEPATH/$KICKSTARTFILENAME64

virt-install --connect qemu:///system \
--name $GUESTNAME64 \

--ram $GUESTRAM \

--vcpus=1 \

--file $GUESTIMAGESTORAGE/$GUESTNAME64$(echo ".")$GUESTIMAGEFORMAT \

--file-size $GUESTDISKSIZE \

--location $REPO64 \

--vnc \

--noautoconsole \

--os-type linux \

--accelerate \

--network=bridge:$NETWORKBRIDGE,mac=00:00:00:00:00:00 \

--hvm \

--initrd-inject=$KICKSTARTFILELOCATION64 \

--extra-args "ks=file:/$KICKSTARTFILENAME64"

#





After running this file I am getting error... .


/home/wahab/Desktop/kickstart/sl63x86_64_ks_base.cfg
ERROR
--name is required
--ram amount in MB is required
--disk storage must be specified (override with --nodisks)
An install method must be specified
(--location URL, --cdrom CD/ISO, --pxe, --import, --boot hd|cdrom|...)
sample_create-1.sh: line 39: --name: command not found
sample_create-1.sh: line 41: --ram: command not found
sample_create-1.sh: line 44: --vcpus=1: command not found
sample_create-1.sh: line 45: --file: command not found
sample_create-1.sh: line 47: --file-size: command not found
sample_create-1.sh: line 49: --location: command not found
sample_create-1.sh: line 52: --vnc: command not found
sample_create-1.sh: line 54: --noautoconsole: command not found
sample_create-1.sh: line 55: --os-type: command not found
sample_create-1.sh: line 58: --accelerate: command not found
sample_create-1.sh: line 60: --network=bridge:guest_os_bridge,mac=00:00:00:00:00:00: command not found
sample_create-1.sh: line 62: --hvm: command not found
sample_create-1.sh: line 64: --initrd-inject=/home/wahab/Desktop/kickstart/sl63x86_64_ks_base.cfg: No such file or directory
sample_create-1.sh: line 65: --extra-args: command not found

Last edited by juniorb0y007; 04-03-2013 at 12:43 PM. Reason: work i did
 
Old 03-30-2013, 05:12 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 15,105

Rep: Reputation: 2720Reputation: 2720Reputation: 2720Reputation: 2720Reputation: 2720Reputation: 2720Reputation: 2720Reputation: 2720Reputation: 2720Reputation: 2720Reputation: 2720
Quote:
Originally Posted by juniorb0y007 View Post
Hello,
I am taking a Linux class right now, and my teacher has requested me to write a bash script. I have been given IP address of the server to create virtual machine on the server. I need someone to help me with this project by getting me started on this project. I have no clue right now how to start this project. Any help will be appreciated. Here is the requirement:

Write a bash script to create a virtual machine running Scientific Linux 6.3, x86_64 architecture. The image should include the telnet client package, the ftp package, and the httpd package. The virtual image should use 1GB of RAM, one virtual CPU, use a 4GB qcow2 disk image, connect to the “virtual_bridge” network bridge using a random MAC address and DHCP boot protocol. The image name should be <user name>. The image should run on an IBM blade server with a Scientific Linux host operating system and KVM hypervisor. You instructor will provide connection credentials in class.
The script must contain:
a title block
conditional debugging output
variables
ample comments
use of positional parameters to enable debugging and the image
We will be happy to HELP you...so post what you've written/tried so far, and where you're stuck. Otherwise, there are lots of very easily-found bash tutorials:
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://tldp.org/LDP/abs/html/

...start with those. As with any programming task in any language, you have to break it down into steps. Think about each task you have to perform...those commands are what's going to make up your bash script. Start there.
 
1 members found this post helpful.
Old 03-30-2013, 05:37 PM   #3
juniorb0y007
LQ Newbie
 
Registered: Mar 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Bash Script

Quote:
Originally Posted by TB0ne View Post
We will be happy to HELP you...so post what you've written/tried so far, and where you're stuck. Otherwise, there are lots of very easily-found bash tutorials:
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://tldp.org/LDP/abs/html/

...start with those. As with any programming task in any language, you have to break it down into steps. Think about each task you have to perform...those commands are what's going to make up your bash script. Start there.
.................................................................................................... ....

Thank you. I just wrote my first hello world script. It executed correctly. I have three weeks to complete this project and I will do my best to get help from the links you provided. Is there anyway you can call me if you are in the USA? I just want to make sure I get this task done and not waste time. My phone number is 336-905-9309. Thanks again.
 
Old 03-30-2013, 07:09 PM   #4
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,583

Rep: Reputation: 480Reputation: 480Reputation: 480Reputation: 480Reputation: 480
you are better off just posting what you have along with either
Code:
bash -xvv OR sh -xvv
when you run a script that is not working properly for you.
 
Old 04-02-2013, 03:02 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
See also this tutorial http://rute.2038bug.com/index.html.gz

I would also (normally) expect that the Lecturer wouldn't ask you to do anything he/she hasn't already covered the core of in class.
 
Old 04-03-2013, 12:44 PM   #6
juniorb0y007
LQ Newbie
 
Registered: Mar 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
here is my work

Quote:
Originally Posted by TB0ne View Post
We will be happy to HELP you...so post what you've written/tried so far, and where you're stuck. Otherwise, there are lots of very easily-found bash tutorials:
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://tldp.org/LDP/abs/html/

...start with those. As with any programming task in any language, you have to break it down into steps. Think about each task you have to perform...those commands are what's going to make up your bash script. Start there.
#!/bin/bash

GUESTIMAGESTORAGE=/home/wahab/Desktop/linux

GUESTIMAGEFORMAT=qcow2

ISOSTORAGE=/home/wahab/Desktop/iso

ISOFILENAME=SL-63-x86_64-2012-08-02-Install-DVD.iso

NETWORKBRIDGE=guest_os_bridge

KICKSTARTFILEPATH=/home/wahab/Desktop/kickstart

GUESTRAM=1024
GUESTDISKSIZE=4

REPO64=http://ftp1.scientificlinux.org/linux/scientific/6.3/x86_64/os
GUESTNAME64=sl63x86_64_base

KICKSTARTFILENAME64=sl63x86_64_ks_base.cfg

KICKSTARTFILELOCATION64=$KICKSTARTFILEPATH/$KICKSTARTFILENAME64

echo "$KICKSTARTFILELOCATION64"

# Create images directory

mkdir -p /home/wahab/Desktop/iso

mkdir -p /home/wahab/Desktop/kickstart

mkdir -p $GUESTIMAGESTORAGE

cp /root/install/$KICKSTARTFILENAME64 $KICKSTARTFILEPATH/$KICKSTARTFILENAME64

virt-install --connect qemu:///system \
--name $GUESTNAME64 \

--ram $GUESTRAM \

--vcpus=1 \

--file $GUESTIMAGESTORAGE/$GUESTNAME64$(echo ".")$GUESTIMAGEFORMAT \

--file-size $GUESTDISKSIZE \

--location $REPO64 \

--vnc \

--noautoconsole \

--os-type linux \

--accelerate \

--network=bridge:$NETWORKBRIDGE,mac=00:00:00:00:00:00 \

--hvm \

--initrd-inject=$KICKSTARTFILELOCATION64 \

--extra-args "ks=file:/$KICKSTARTFILENAME64"

#





After running this file I am getting error... .


/home/wahab/Desktop/kickstart/sl63x86_64_ks_base.cfg
ERROR
--name is required
--ram amount in MB is required
--disk storage must be specified (override with --nodisks)
An install method must be specified
(--location URL, --cdrom CD/ISO, --pxe, --import, --boot hd|cdrom|...)
sample_create-1.sh: line 39: --name: command not found
sample_create-1.sh: line 41: --ram: command not found
sample_create-1.sh: line 44: --vcpus=1: command not found
sample_create-1.sh: line 45: --file: command not found
sample_create-1.sh: line 47: --file-size: command not found
sample_create-1.sh: line 49: --location: command not found
sample_create-1.sh: line 52: --vnc: command not found
sample_create-1.sh: line 54: --noautoconsole: command not found
sample_create-1.sh: line 55: --os-type: command not found
sample_create-1.sh: line 58: --accelerate: command not found
sample_create-1.sh: line 60: --network=bridge:guest_os_bridge,mac=00:00:00:00:00:00: command not found
sample_create-1.sh: line 62: --hvm: command not found
sample_create-1.sh: line 64: --initrd-inject=/home/wahab/Desktop/kickstart/sl63x86_64_ks_base.cfg: No such file or directory
sample_create-1.sh: line 65: --extra-args: command not found
 
Old 04-03-2013, 11:49 PM   #7
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
You may have blank lines in bash IF(!) the cmd does not continue onto the next line.
Even using '\' only appends the next (physical) line, not the next useful/logical line.
Try removing the blank lines starting at virt-install ...
http://linux.dell.com/files/whitepap..._made_easy.pdf

See also the useful links you've been given above; you need to read them.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does this work from the bash command line and then fails in a bash script? Rupadhya Linux - Newbie 5 09-26-2012 01:05 AM
[SOLVED] Run multiple bash and php scripts from a bash script charu Programming 5 07-26-2011 03:40 AM
Variables and Mkvextract in a bash script and a good resource for bash help? gohmifune Linux - General 9 04-13-2011 09:37 AM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 09:56 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 12:10 PM


All times are GMT -5. The time now is 10:54 AM.

Main Menu
Advertisement
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