Combining two scripts into a single script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combining two scripts into a single script
# 1  
Old 09-19-2013
Wrench 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
HTML Code:
/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,

Code:
$ 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.
# 2  
Old 09-19-2013
Hello,

You can put a single script by using keyword named
Code:
 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.

Code:
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
Code:
 case

command, hope this will help you.




Thanks,
R. Singh
# 3  
Old 09-19-2013
Why all the separate scripts? You could use a case statement and incorporate all the functions into a single script.

i.e.
Code:
case "$1" in
      start) do something
               ;;
       stop) do something
               ;;
    restart) do something
               ;;
     status) do something
               ;;
        *) display usage
esac

# 4  
Old 09-19-2013
Wrench

Quote:
Originally Posted by in2nix4life
Why all the separate scripts? You could use a case statement and incorporate all the functions into a single script.

i.e.
Code:
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..
Code:
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
# 5  
Old 09-19-2013
And, you could add /opt/app/tre to your path so you don't need to cd to and fro.
# 6  
Old 09-19-2013
Hello,

Could you please try as following.

Code:
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

Last edited by RavinderSingh13; 09-19-2013 at 12:57 PM.. Reason: a littile edditing
# 7  
Old 09-19-2013
Wrench

Quote:
Originally Posted by RavinderSingh13
Hello,

Could you please try as following.

Code:
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.


PHP Code:
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..


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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Log4j combining lines to single line

Hi, Our log4j file contents look like this: 2018-11-20T00:06:58,888 INFO ql.Driver: Executing command(queryId=hive_20181120000656_49af4ad0-1d37-4312-872c-a247ed80c181): CREATE TABLE RESULTS.E7014485_ALL_HMS_CAP1 AS SELECT name,dept from employee Where employee='Jeff'... (4 Replies)
Discussion started by: wahi80
4 Replies

2. Shell Programming and Scripting

Combining lines into a single line

i have a file (where the column values are separated by ' and the text can be enclosed in ~) which contains data in form of 4461,2,~Basic: 2 Years/Unlimited Miles Drivetrain: Gas Engine 2 Years/Unlimited Miles Duramax Engine 3 Years/Unlimited... (2 Replies)
Discussion started by: rahulchandak
2 Replies

3. Shell Programming and Scripting

Multiple scripts in one single script - crontab

Hello all, Hope all's well. i'm not sure if this is possible but i have some scripts running in a crontab with different intervals, 1min, 5 min, etc. As for a "cleaner" and better control of these scripts (as by time we will have hundred's of scripts used for the same purpose, i.e for Nagios... (4 Replies)
Discussion started by: nms
4 Replies

4. UNIX for Beginners Questions & Answers

A single script to run multiple scripts

Hi , Can someone help! I need a shell script to run multiple scripts by using single shell script, incase any one of the scripts fails, it should get exit and after trouble shooting if we re-execute it, it should start from the failed script. I have a written a scripting till the... (1 Reply)
Discussion started by: anniesurolyn
1 Replies

5. Programming

PERL:Combining multiple lines to single line

Hi All I need a small help for the below format in making a small script in Perl or Shell. I have a file in which a single line entries are broken into three line entries. Eg: I have a pen and notebook. All i want is to capture in a single line in a separate file. eg: I have a pen and... (4 Replies)
Discussion started by: Kalaiela
4 Replies

6. Shell Programming and Scripting

Combining two shell scripts

Hi readers, I have two shell scripts running on linux machine. Both the scripts do the following task - Connect to DB - Create temp files - run select statement on table - write the rows returned on temp file Sample code is below #!/bin/sh export ORACLE_HOME=/content/oracle/10.2.0... (1 Reply)
Discussion started by: manucorbi
1 Replies

7. Shell Programming and Scripting

Combining two awk scripts

I have a file like this consisting of blocks separated by > of two number X and T > 10 0 13 5.92346 16 10.3106 19 13.9672 22 16.9838 25 19.4407 28 21.4705 31 23.1547 34 24.6813 37 26.0695 40 27.3611 43 28.631 46 29.8366 49 30.9858 52 32.0934 55 33.1458 (6 Replies)
Discussion started by: kristinu
6 Replies

8. Shell Programming and Scripting

combining perl regex'es into a single command

Hi Gurus, I have a working solution for munging my data but just wondered if there was a way I could streamline it into a single command at all ? my $filesystem = "backup/server56/oracle/" $filesystem =~ s/\/+$// ; # remove the trailing slash(es) from the path specified... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

9. Shell Programming and Scripting

combining two scripts

Hi , Following are the two scripts :- Script 1) #!/bin/sh cp file.log file.log.1 Script 2) #!/bin/sh diff file.log file.log.1 > DIFFERENCE.log cp file.log file.log.1 grep "ERROR" DIFFERENCE.log if ; then echo "1" else echo "0" fi (1 Reply)
Discussion started by: himvat
1 Replies

10. Shell Programming and Scripting

Combining 2 scripts

Hello I am new to shell scripting. Below are 2 scripts which I need to combine in to single script.Can some experts guide me how to proceed? #!/bin/bash grep "2443" /f/log/s/heduler.log | grep 2443> /tmp/memorydump exec 6<"/tmp/memorydump" read -u 6 data if then echo "IN THEN" <... (4 Replies)
Discussion started by: achararun
4 Replies
Login or Register to Ask a Question