LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-28-2012, 08:24 AM   #1
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Rep: Reputation: Disabled
How we can run script for muliple home(users)


Hi All,

I am very new to Linux scripting. I m trying to write one script to start/stop our SAP application . Below is my scenrio
1:- I have 4 instances running on same physical (diffrent virtual box) box

Below is the sample script which i have devloped for one instance

#!/sbin/sh

#

# Start / stop SAP

case "$1" in

"start")

su - oraepn -c "lsnrctl start LISTENER_EPN"

su - epnadm -c "startsap"

;;

"stop")

su - epnadm -c "stopsap"

su - oraepn -c "lsnrctl stop LISTENER_EPN"

;;

*)

echo "Usage: $0 { start|stop }"

exit 1

;;

esac

exit 0

The above script is working fine with one insatce call EPN .
Now the question is how can i add my other instance in this script for EX:- EPP,EPX (application owner "eppadm" & "epxadm")
 
Old 08-28-2012, 09:24 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,870
Blog Entries: 14

Rep: Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112
Since you say what you have is working I'm assuming it is running as root?

If the current "su - c" commands are working and the script is exiting when done you should be able to just add additional "su -c" commands below the ones you have and specify the alternate users.


Code:
#!/sbin/sh

#

# Start / stop SAP

case "$1" in

"start")

su - oraepn -c "lsnrctl start LISTENER_EPN"

su - epnadm -c "startsap"

su - oraepp -c "lsnrctl start LISTENER_EPP"

su - eppadm -c "startsap"

su - oraexp -c "lsnrctl start LISTENER_EXP"

su - expadm -c "startsap"

;;

"stop")

su - epnadm -c "stopsap"

su - oraepn -c "lsnrctl stop LISTENER_EPN"

su - eppadm -c "stopsap"

su - oraepp -c "lsnrctl stop LISTENER_EPP"

su - expadm -c "stopsap"

su - oraexp -c "lsnrctl stop LISTENER_EXP"

;;

*)

echo "Usage: $0 { start|stop }"

exit 1

;;

esac

exit 0
In above I've assumed your naming is consistent. A couple of caveats.

1) sh is often a symbolic link to other shells (e.g. bash or dash). You might want to make your interpreter line specify the shell you expect (the one linked to) rather than the symbolic link - that way if you put it on another system later it is clear which shell you want.

2) If any of your su commands hung above then the next ones wouldn't execute. For that reason you might want to have separate scripts that did just the listener start and SAP start or stop for each instance and call those scripts from within this master script putting an ampersand (&) at the end of each line. The & tells it to run the command in the background rather than waiting for it to complete. The reason I suggest separate scripts called from master is you want to start two processes (listener and SAP) rather than one for each instance. If you did & after each individual of those then they might not start in the order you want. Presumably you care about whether listener or SAP starts first but don't care which instance starts first.

3) You don't have the commands being output to a log. Often it is a good idea to do that. If you add something like ">> /var/log/eppstart.log 2>&1" to the end of your epp start commands then you'll capture any output from those commands into the file and it will help you debug failure if any occurs. If you did this then you'd put a final & after the redirects to do the backgrounding discussed above.

4) Start/Stop implies you're doing this as an init script for automatic stop/start at boots. Be aware that often init scripts have different requirements to run automatically at boot then they do at command line. You should do test boots to verify they work now as opposed to waiting for a system crash later to find out they don't if you intend to use them for automatic stop/start for boots. The syntax needed for init scripts can very with your distribution and version of Linux.
 
2 members found this post helpful.
Old 08-28-2012, 09:34 AM   #3
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,204

Rep: Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611Reputation: 1611
Nice job MensaWater, I'm giving you rep just for the sheer Volume of information you helped with.

Just wondering if OP was asking how to integrate "nested case"? So they can run a command like...

Code:
blah start thing-1
blah start thing-2
blah stop thing-1
 
Old 08-28-2012, 09:53 AM   #4
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
Hi MensaWater,

Thanks for REply!!

My script is working fine now.

Now as per your point 2 if i have to call sript only for one system call EPP from master script than can you please guide me how can i put all needed steps in master script.

Please also let me know how can i reward you points for this help.
 
Old 08-28-2012, 10:12 AM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,870
Blog Entries: 14

Rep: Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112
Basically you'd create your 3 individual scripts to look very much like your original so that each starts only a single instance (SAP and Listener) of course using the different su commands for each as appropriate to the instance. Call them say, epn_init.sh, exp_init.sh and epp_init.sh. You'd then modify your mast to have:

Code:
#!/sbin/sh

#

# Start / stop SAP

case "$1" in

"start")

epp_init.sh start >>/var/log/epp_start.log 2>&1  &

exp_init.sh start >>/var/log/exp_start.log 2>&1  &

epn_init.sh start >>/var/log/epn_start.log 2>&1  &

;;

"stop")

epp_init.sh stop >>/var/log/epp_stop.log 2>&1  &

exp_init.sh stop >>/var/log/exp_stop.log 2>&1  &

epn_init.sh stop >>/var/log/epn_stop.log 2>&1  &

;;

*)

echo "Usage: $0 { start|stop }"

exit 1

;;

esac

exit 0
To start all 3 instances you runt he master script.

To start only epp you'd then run the "epp_init.sh start" rather than the master script.

To give points you can just click on Yes for finding this post useful or you can kick on the little scales symbol and say you approve.

Last edited by MensaWater; 08-28-2012 at 10:13 AM.
 
Old 08-29-2012, 04:38 AM   #6
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
Hi MensaWater,

I realy appricate your help!!

I will make one master script (Start_stop_SAP.sh) for all system like EPP, EPX,EPN..etc & also i will make single script for each system ex:- start_stop_EPP.sh.

Now my concern is how i integrate all these single script with master script. I want to make script like below

If i want to start EPP than i execute "./Start_stop_sap.sh stop/start EPP" than only EPP stop/start.
 
Old 08-29-2012, 10:38 AM   #7
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
Can anyone please guide me to devlop this script
 
Old 08-29-2012, 12:21 PM   #8
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,870
Blog Entries: 14

Rep: Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112
You can have two variables at command line which will be $1 and $2.

In the script set those to new variables near the start of the script (after the interpreter line of course).
ACTION=$1
INST=$2

You change your existing case for "in $ACTION" instead of "in $1".

You can nest a new case within each of the actions (start and stop) and give the options for that case (e.g.)
case $INST in
EPP|epp) ...
;;
EXP|exp) ...
;;
EPN|epn) ...
;;
ALL|all) ...
;;
*) Usage...
esac

Within ALL you do what the current script does. Within the other options you do only the two su commands to start the Listener and SAP Application for that instance. The UPPER|lower format allows the user to enter the instance name (or all) in either upper or lower and get the same results.
 
1 members found this post helpful.
Old 08-30-2012, 06:54 AM   #9
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
Hi MensaWater,

Thannks for help!!

As per your guidance. I have made changes in my script but it is giving me syntax error. For example i have done only for one command. Please have a look if it is correct or need to be modify.

#!/bin/sh

#

# Start / stop SAP

Action=$1
Inst=$2

case "$Action" in

"start")

case "$Inst" in
"PIN")
su - pinadm -c "startsap r3"

;;

"BPN")
su - bpnadm -c "startsap r3"

;;

"ECN")
su - ecnadm -c "startsap r3"

;;

"ALL")
su - pinadm -c "startsap r3"
su - bpnadm -c "startsap r3"
su - ecnadm -c "startsap r3"
;;
*)





"stop")


case "$Inst" in
"PIN")
su - pinadm -c "stopsap r3"

;;

"BPN")
su - bpnadm -c "stopsap r3"

;;

"ECN")
su - ecnadm -c "stopsap r3"

;;

"ALL")
su - pinadm -c "stopsap r3"
su - bpnadm -c "stopsap r3"
su - ecnadm -c "stopsap r3"
;;
*)

echo "Usage: $0 { start|stop }"

exit 1

;;

esac
 
Old 08-30-2012, 07:51 AM   #10
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Original Poster
Rep: Reputation: Disabled
Hi MeansWater,

Thanks for your help!!

My script is working now. I forget to write *) & esac end of the second case statment.

Now i am working on this script to make more efficative.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to edit /etc/sudoers so that I can run another users script vanish78 Linux - Newbie 6 05-15-2011 02:28 PM
run script when a users prints Elcrapocrew Linux - Desktop 2 06-28-2010 04:45 PM
how to run a script in startup linux or logs on users kavehiks Linux - General 1 10-22-2009 05:22 PM
prevent users to run the same script at the same time, on the same machine pvpnguyen Programming 2 09-05-2007 08:52 PM
script to rename muliple files cranium2004 Programming 3 02-21-2006 10:59 PM


All times are GMT -5. The time now is 08:26 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration