LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-24-2009, 03:03 AM   #1
ramjgn
LQ Newbie
 
Registered: Jan 2009
Posts: 19

Rep: Reputation: 0
shell for creating repository


hi , i`m writing a shell script to create repository in Server. I need to interactively choose the source. The source is either DVD or CD . I have written a shell script but the second condition is not getting executed. Only the first choice is getting executed. Kindly help me.


#! /bin/bash
echo " starting process to create repository"
sch=0
echo -n "Select your source choice [1 or 2]? "
echo "1. dvd"
echo "2. cd"
read sch
if [ $sch -eq 1 ] ; then
echo " you have chosen to use DVD as source"
sleep 2
echo " starting the process"
sleep 1
eject -m
sleep 5
eject -t
echo "mounting the device"
sleep 2
mount /dev/cdrom /mnt
echo "changing directory"
sleep 1
cd /mnt/Server
sleep 2
echo "installing vsftpd to create public shareable folder /var/ftp/pub/Server"
rpm -ivh vsftpd-2.0.5-10.el5.i386.rpm
cd /mnt
echo "starting the copy process"
sleep 2
echo " copying may take several minutes"
cp -irv . /var/ftp/pub
cd
umount /mnt
eject -m
sleep 5
eject -t
echo "changing directory"
sleep 1
cd /var/ftp/pub/Server/repodata/
echo "copying the .xml file"
sleep 1
cp comps-rhel5-server-core.xml /opt/
echo "changing directory to /var/ftp/pub/Server"
sleep 1
cd ..
rpm -ivh createrepo-0.4.4-2.fc6.noarch.rpm
echo "changing to root`s home folder"
cd
echo "creating repository"
sleep 1
createrepo -g /opt/comps-rhel5-server-core.xml -v /var/ftp/pub/Server
echo " removing the old data"
sleep 1
rm -rf /var/ftp/pub/Server/.olddata
echo " successfully created repository using DVD "
else if [ $sch -eq 2 ] ; then

echo " you have chosen to use CD as source"
echo "enter second cd"
eject -m
sleep 5
eject -t
echo "mounting the device"
mount /dev/cdrom /mnt
cd /mnt/Server
echo "installing vsftpd to create public shareable folder /var/ftp/pub/Server"
sleep 1
rpm -ivh vsftpd-2.0.5-10.el5.i386.rpm
cd
umount /mnt
eject -m
echo " enter the first cd"
sleep 5
mount /dev/cdrom /mnt
cd /mnt
cp -rv . /var/ftp/pub
cd
umount /mnt
eject -m
echo "enter the second cd"
sleep 5
mount /dev/cdrom /mnt
cd /mnt/Server
cp -irv . /var/ftp/pub/Server
cd
umount /mnt
eject -m
echo "enter the third cd"
sleep 5
mount /dev/cdrom /mnt
cd /mnt/Server
cp -irv . /var/ftp/pub/Server
cd
umount /mnt
eject -m
echo "enter the fourth cd"
sleep 5
mount /dev/cdrom /mnt
cd /mnt/Server
cp -irv . /var/ftp/pub/Server
cd
umount /mnt
eject -m
echo "enter the fifth cd"
sleep 5
mount /dev/cdrom /mnt
cd /mnt/Server
cp -irv . /var/ftp/pub/Server
cd
umount /mnt
eject -m
sleep 5
eject -t
echo "changing directory"
sleep 1
cd /var/ftp/pub/Server/repodata/
echo "copying the .xml file"
sleep 1
cp comps-rhel5-server-core.xml /opt/
echo "changing directory to /var/ftp/pub/Server"
sleep 1
cd ..
rpm -ivh createrepo-0.4.4-2.fc6.noarch.rpm
echo "changing to root`s home folder"
cd
echo "creating repository"
sleep 1
createrepo -g /opt/comps-rhel5-server-core.xml -v /var/ftp/pub/Server
echo " removing the old data"
sleep 1
rm -rf /var/ftp/pub/Server/.olddata
echo " successfully created repository using cd"
else
echo "invalid input"
fi
fi




whats the problem in above script????? Only DVD choice is getting executed. The loop for CD fails.
 
Old 03-24-2009, 04:53 AM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Wow, such a lot of code without using the CODE tags makes me 'sleepy'. Please enclose your code in CODE tags so it can be read. And if it still doesn't have some indentation, don't expect many to read it anyway. Use some basic formatting in your code for readability, please.
 
Old 03-24-2009, 06:21 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Try to use the construct
Code:
if expression
then
  do something
elif expression
  do something else
else
  echo invalid input
fi
or eventually the case/esac construct, using *) as "any other choice" for invalid input.
 
Old 03-25-2009, 07:16 AM   #4
ramjgn
LQ Newbie
 
Registered: Jan 2009
Posts: 19

Original Poster
Rep: Reputation: 0
well, i tried but i didnt work. i have found a better way!!!1 i have split cd and dvd scripts in two and in third script, i used a case which will call the cd and dvd scripts, located in same location.


masterscript.sh

tput clear

echo " starting process to create repository"
n=0
echo "Select your source choice [1 or 2]? "
echo "1. dvd"
echo "2. cd"
read n
case "$n" in
1) sh dvds
;;
2) sh cds
;;
3) echo invalid option
;;
esac


dvds


echo " you have chosen to use DVD as source"
sleep 2
echo " starting the process"
sleep 1
eject -m
sleep 5
eject -t
echo "mounting the device"
sleep 2
mount /dev/cdrom /mnt
echo "changing directory"
sleep 1
cd /mnt/Server
sleep 2
echo "installing vsftpd to create public shareable folder /var/ftp/pub/Server"
rpm -ivh vsftpd-2.0.5-10.el5.i386.rpm
cd /mnt
echo "starting the copy process"
sleep 2
echo " copying may take several minutes"
cp -irv . /var/ftp/pub
cd
umount /mnt
eject -m
sleep 5
eject -t
echo "changing directory"
sleep 1
cd /var/ftp/pub/Server/repodata/
echo "copying the .xml file"
sleep 1
cp comps-rhel5-server-core.xml /opt/
echo "changing directory to /var/ftp/pub/Server"
sleep 1
cd ..
rpm -ivh createrepo-0.4.4-2.fc6.noarch.rpm
echo "changing to root`s home folder"
cd
echo "creating repository"
sleep 1
createrepo -g /opt/comps-rhel5-server-core.xml -v /var/ftp/pub/Server
echo " removing the old data"
sleep 1
rm -rf /var/ftp/pub/Server/.olddata
echo " successfully created repository using DVD "


cds


echo " you have chosen to use CD as source"
echo "enter second cd"
eject -m
sleep 5
eject -t
echo "mounting the device"
mount /dev/cdrom /mnt
cd /mnt/Server
echo "installing vsftpd to create public shareable folder /var/ftp/pub/Server"
sleep 1
rpm -ivh vsftpd-2.0.5-10.el5.i386.rpm
cd
umount /mnt
eject -m
echo " enter the first cd"
sleep 5
mount /dev/cdrom /mnt
cd /mnt
cp -rv . /var/ftp/pub
cd
umount /mnt
eject -m
echo "enter the second cd"
sleep 5
mount /dev/cdrom /mnt
cd /mnt/Server
cp -irv . /var/ftp/pub/Server
cd
umount /mnt
eject -m
echo "enter the third cd"
sleep 5
mount /dev/cdrom /mnt
cd /mnt/Server
cp -irv . /var/ftp/pub/Server
cd
umount /mnt
eject -m
echo "enter the fourth cd"
sleep 5
mount /dev/cdrom /mnt
cd /mnt/Server
cp -irv . /var/ftp/pub/Server
cd
umount /mnt
eject -m
echo "enter the fifth cd"
sleep 5
mount /dev/cdrom /mnt
cd /mnt/Server
cp -irv . /var/ftp/pub/Server
cd
umount /mnt
eject -m
sleep 5
eject -t
echo "changing directory"
sleep 1
cd /var/ftp/pub/Server/repodata/
echo "copying the .xml file"
sleep 1
cp comps-rhel5-server-core.xml /opt/
echo "changing directory to /var/ftp/pub/Server"
sleep 1
cd ..
rpm -ivh createrepo-0.4.4-2.fc6.noarch.rpm
echo "changing to root`s home folder"
cd
echo "creating repository"
sleep 1
createrepo -g /opt/comps-rhel5-server-core.xml -v /var/ftp/pub/Server
echo " removing the old data"
sleep 1
rm -rf /var/ftp/pub/Server/.olddata
echo " successfully created repository using cd"


i`m able to execute it without any problem. Thanks for ur reply
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating A Local Debian Repository ashmita04 Debian 1 01-23-2008 03:28 PM
Creating YUM Repository Charles_In_Charge Linux - Newbie 6 09-07-2006 06:02 PM
Creating a package repository Thakowbbery SUSE / openSUSE 0 10-13-2005 08:40 AM
Creating A Yum Repository SepitvaOra Linux - Newbie 1 04-04-2005 06:54 AM
Creating CVS repository: cvs [import aborted]: attempt to import the repository enemorales Linux - Software 3 10-15-2004 04:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:33 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
Open Source Consulting | Domain Registration