Combining two scripts into a single script

Hi Folks,

I have two scripts that are used to start and stop services these scripts are at the location

/opt/app/tre

, so that start.sh internally starts the components and stop.sh internally stop all the components, now rite now if I have to stop the services then i need to go first the location where all the scripts are there then I need to execute the stop script and then in between doing some work again need to start the services ..besides there is another script status (status.sh) by which I check the status, so the cycle follows as first stop the services then check the status which confirms that services are stop and then in between doing some work so the interval is of 40 seconds and then again starting the components by executing the start.sh,

$ cd  /opt/app/tre
sh stop.sh
sh status.sh
sh start.sh
sh status.sh

so rite now I want to develop another script and the name of this script will be restart.sh that will internally first call my stop.sh script then it will show that status by calling my status.sh script then it will sleep for 40 seconds and then again it will start the components and then will again show the status please advise how to develop these restart.sh script.

Hello,

You can put a single script by using keyword named

 case 

and you can create a menu script in which you can put all options like Stop, Start and Check the service status, here is an example.

Menu:
1) Stop services owned by Singh
2) Start services owned by Singh
3) Status for services owned by Singh
4) exit

You need to simple call all script in one script by using the

 case

command, hope this will help you.

Thanks,
R. Singh

Why all the separate scripts? You could use a case statement and incorporate all the functions into a single script.

i.e.

case "$1" in
      start) do something
               ;;
       stop) do something
               ;;
    restart) do something
               ;;
     status) do something
               ;;
        *) display usage
esac

Thanks a lot could you please advise then how will be the final script , the scripts involved in my case are..

Stop.sh
Status.sh
Start.sh

so I will exceut the script like

sh restart.sh

but please advise the cod that will be in restart.ch

And, you could add /opt/app/tre to your path so you don't need to cd to and fro.

Hello,

Could you please try as following.

one=1
status=1
clear
while [[ $status -eq $one ]]
do
echo "Please enter the appropriate choice for doing the operations"
echo "
1) STOP instance       
2) START instance    
3) Check status of instance    
Enter choice below
@@"
read choice
 
case $choice
in
1)
echo "Stopping instances."
call STOP script here
2)
echo "starting instances"
Call START script here.
 
3)
echo "checking instances"
Call Status script here.
 
*) echo "You have entered an invalid choice";;
esac
echo "\n\n"
echo "Please enter 1(Digit) if you want to continue with menu script, enter 0(digit) to come out of it"
read status
 
done
 

Hope it may help you.

Thanks,
R. Singh

Thanks a lot the 4 th choice that I want is the start stop simentously with a 40 seconds gap in between that is service will stop first , and status will be printed and then 40 seconds break will be there and then services will be restarted and again the status will be printed , I have all the scripts ready I just need to call them as you advise.

second query is that as you mention...
case $choice
in
1)
echo "Stopping instances."
call STOP script here

so in the place of call STOP script can I call directly my stop script like as shown below..

case $choice
in
1)
echo "Stopping instances."
stop.sh 
   

I guess you want this:

4)  stop.sh
    status.sh
    sleep 40
    start.sh
    status.sh
    ;;

You know the select command for building menus?

yes, you can put as follows.

case $choicein1)echo "Stopping instances."stop.sh;;

Please don't forget to put semicolons at end of the statement.

Thanks,
R. Singh[/LEFT]

Perfect this what I am looking for in sidae a script say resstart.sh, so i will cal the script like sh restart.sh that will internally do the processing in this order and it will internally call my scripts so please advise how to achieve this ,Thanks in advance..!!