LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bash Script (https://www.linuxquestions.org/questions/linux-general-1/bash-script-4175456183/)

juniorb0y007 03-30-2013 03:23 PM

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

TB0ne 03-30-2013 04:12 PM

Quote:

Originally Posted by juniorb0y007 (Post 4921774)
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.

juniorb0y007 03-30-2013 04:37 PM

Bash Script
 
Quote:

Originally Posted by TB0ne (Post 4921800)
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.

lleb 03-30-2013 06:09 PM

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.

chrism01 04-02-2013 02:02 AM

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.

juniorb0y007 04-03-2013 11:44 AM

here is my work
 
Quote:

Originally Posted by TB0ne (Post 4921800)
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

chrism01 04-03-2013 10:49 PM

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.


All times are GMT -5. The time now is 07:11 AM.