ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.