LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 03: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 11:43 AM. Reason: work i did
 
Old 03-30-2013, 04:12 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
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, 04: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, 06:09 PM   #4
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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, 02:02 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 11:44 AM   #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, 10:49 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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



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 12:05 AM
[SOLVED] Run multiple bash and php scripts from a bash script charu Programming 5 07-26-2011 02:40 AM
Variables and Mkvextract in a bash script and a good resource for bash help? gohmifune Linux - General 9 04-13-2011 08:37 AM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:53 PM.

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
Open Source Consulting | Domain Registration