This Page will make us learn : If Else Loop, Linux Shell Scripts, Unix Shell Scripts Accepting Inputs, Shell Scripts with Nested If Else loop, Unix Programming.
#!/usr/bin/bash
# ------------------------------------------------------------------
# Author : Rahul Miglani
# Date : XX/XX/XXXX
# Description : This script allows you to run Scripts depending on your choices
# ------------------------------------------------------------------
# let us first take the input where in we will see if we have to run scripts in environment 1 or environment 4
echo "Please enter 1 for ENV1 and 4 for ENV4"
read option
if [ "$option" == "1" ]; then
cd /usrdev/imagineua/ENV1/eodbatch/prd;
#if we have chosen environment 1 we have actually changed the path so that we can pick up the exact #scripts
pwd;
echo "Please enter ATD,HK or KR"
read region
if [ "$region" == "ATD" ]; then
echo "Please enter 1 for non NB and 2 for NB"
read choice
if [ "$choice" == "1" ]; then
echo "you choose ENV$option , $region and NON NB"
nohup ./startEODScheduler.ATD-ENV1 &
elif [ "$choice" == "2" ]; then
echo "you choose ENV$option , $region and NB"
nohup ./startEODScheduler.NB.ATD-ENV1 &
else echo "You Have not made the correct choice for 1 for Non NB and 2 for NB exiting Now..."
exit;
fi
elif [ "$region" == "HK" ]; then
echo "Please enter 1 for non NB and 2 for NB"
read choice
if [ "$choice" == "1" ]; then
echo "you choose ENV$option , $region and NON NB"
nohup ./startEODScheduler.HK-ENV1 &
elif [ "$choice" == "2" ]; then
echo "you choose ENV$option , $region and NB"
nohup ./startEODScheduler.NB.HK-ENV1 &
else echo "You Have not made the correct choice for 1 for Non NB and 2 for NB exiting Now..."
exit;
fi
elif [ "$region" == "KR" ]; then
echo "Please enter 1 for non NB and 2 for NB"
read choice
if [ "$choice" == "1" ]; then
echo "you choose ENV$option , $region and NON NB"
nohup ./startEODScheduler.KR-ENV1 &
elif [ "$choice" == "2" ]; then
echo "you choose ENV$option , $region and NB"
nohup ./startEODScheduler.NB.KR-ENV1 &
else echo "You Have not made the correct choice for 1 for Non NB and 2 for NB exiting Now..."
#This is the exit of this loop only
exit;
fi
#This is the exit of second if else loop only
else echo "You Have not made the correct choice for ATD,HK or KR ... exiting Now..."
exit;
fi
elif [ "$option" == "4" ]; then
cd /usrdev/imagineua/ENV4/eodbatch/prd;
pwd;
echo "Please enter ATD,HK or KR"
read region
if [ "$region" == "ATD" ]; then
echo "Please enter 1 for non NB and 2 for NB"
read choice
if [ "$choice" == "1" ]; then
echo "you choose ENV$option , $region and NON NB"
nohup ./startEODScheduler.ATD-ENV4 &
elif [ "$choice" == "2" ]; then
echo "you choose ENV$option , $region and NB"
nohup ./startEODScheduler.NB.ATD-ENV4 &
else echo "You Have not made the correct choice for 1 for Non NB and 2 for NB exiting Now..."
exit;
fi
elif [ "$region" == "HK" ]; then
echo "Please enter 1 for non NB and 2 for NB"
read choice
if [ "$choice" == "1" ]; then
echo "you choose ENV$option , $region and NON NB"
nohup ./startEODScheduler.HK-ENV4 &
elif [ "$choice" == "2" ]; then
echo "you choose ENV$option , $region and NB"
nohup ./startEODScheduler.NB.HK-ENV4 &
else echo "You Have not made the correct choice for 1 for Non NB and 2 for NB exiting Now..."
exit;
fi
elif [ "$region" == "KR" ]; then
echo "Please enter 1 for non NB and 2 for NB"
read choice
if [ "$choice" == "1" ]; then
echo "you choose ENV$option , $region and NON NB"
nohup ./startEODScheduler.KR-ENV4 &
elif [ "$choice" == "2" ]; then
echo "you choose ENV$option , $region and NB"
nohup ./startEODScheduler.NB.KR-ENV4 &
else echo "You Have not made the correct choice for 1 for Non NB and 2 for NB exiting Now..."
#This is the exit of this loop only
exit;
fi
else echo "You Have not made the correct choice for ATD,HK or KR ... exiting Now..."
#this is the exit of second if else loop
exit;
fi
else echo "Exiting Now : Please Either Choose 1 for ENV1 or 4 for ENV4"
#this is the exit of first if else loop
fi
So we See We have used 3 nested if else loop,First Loop Makes the choice of env1 and env4 which actually just changes the path.Second loop just choose the Script name Third Loops Also Chooses the Script name
No comments:
Post a Comment