[SOLVED] How we can run script for muliple home(users)
Linux - NewbieThis 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
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.
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")
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.
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.
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:
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.
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.
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"
;;
*)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.