Running a script as root but with different users inside


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a script as root but with different users inside
# 8  
Old 06-03-2014
Hi I need to bring down apps and reboot the servers .. this is still a plan. I haven't started yet. . Please suggest best way to reboot using a script. So that I can schedule a cron.
I am on solaris 10.
# 9  
Old 06-03-2014
You can write a wrap up script and place it under rcX.d (for AIX it is runlevel 2, Figure out what is the multiuser level for Solaris) under /etc/rc.d directory.

To start it use capital S and to stop use capital K on the script.

This will bring down the application before rebooting the box.
# 10  
Old 06-03-2014
Hey thanks for replying, have few points here. I am trying to automate the reboot,

with out touching rc3.d, I need to do this, as i have to get lot of approvals for that.

My code
Code:
sudo -t wam /usr/local/wam/stopwam -r     ------- this needs run as wam user
/usr/local/web/stopweb -a                             --- this needs to run as root
/sbin/init 6       ---- Is it safe to use this command for reboot?

for this as per above suggestion i have used
Code:
su -u wam -c <command> <args>

, this failed, I have to test this week with below
Code:
su -u wam -c "<command> <args>"

,

Also please suggest if any, Is it safe to reboot the server issuing init 6.
# 11  
Old 06-04-2014
I would strongly suggest:-
Code:
echo "su - wam -c "/usr/local/wam/stopwam -r" > /etc/rc.d/rc3.d/K00wam
echo "/usr/local/wam/stopwam -r"  > /etc/rc.d/rc3.d/K00wam

.... then whenever you choose to boot, these will run. If the server detects something critical and goes into an emergency shutdown itself this will get run, e.g. critical power failure, overheating etc.


The OS is Solaris so I'm assuming that the path I have used is correct. You may need to adjust that. I haven't got a Solaris available to me.

Is there a reason that you don't want to work in the rc3.d directory? It is the standard place that you are encouraged to customise.



Regards,
Robin

Last edited by rbatte1; 06-04-2014 at 07:30 AM.. Reason: Didn't notice that the OS was indeed stated
This User Gave Thanks to rbatte1 For This Post:
# 12  
Old 06-04-2014
Hi,

I have a different boot scripts in the same directory to start the applcations,

Here i need to bring down the applications and reboot the box.
# 13  
Old 06-04-2014
Your start scripts are presumable named S.... If you read the script that calls these (possibly /etc/rc or /etc/rc.boot) you can read what it does an in what order. Assuming that you still have a fairly full /etc/inittab, it will be in a line towards the end that gives most (if not all) run levels in the second column.

Setting up K... scripts is perfectly standard stuff, most usually the scripts are actually in /etc/init.d or somewhere with links to it from /etc/rc.d/rc3.d, or wherever else is required.



Robin
This User Gave Thanks to rbatte1 For This Post:
# 14  
Old 06-04-2014
thanks guys !! .
/etc/rc3.d is the dir.
i have copied my script which has other commands to /etc/rc3.d
..
Please accept my apology for being so basic..
As per my understanding till now, If we initiate a reboot, the scripts in rc3.d will run (which will bring down my apps)

Now, As mentioned above init or shutdown commands are not safe to initiate a reboot. could you help me with a best script or commands to initate a reboot.


Thanks in Advance !!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Parsing Root password inside a C shell script

Hello everyone, I want to check how long a remote computer is running (e.g. with the command uptime or who - b) The check should be done during login from none root user by a script which is called from .cshrc. My script works fine if I login as root but I want that everybody get the information... (5 Replies)
Discussion started by: Nadielosabra
5 Replies

2. Shell Programming and Scripting

Running .sh file inside a shell script

Hello, You might help a newbie like me, I am trying to run a .sh inside my shell script. After running that I need to execute below commands. Here's how my scripts looks like. Hope you can help: #!/bin/sh cd $ORACLE_HOME/owb/bin/unix ./OMBPlus.sh ---> goes to OMB+> directory cd... (10 Replies)
Discussion started by: aderamos12
10 Replies

3. Shell Programming and Scripting

help in running while loop inside a shell script

I have an input file at ./$1.txt with content of seq numbers like : 1234567890 1234589700 . . so on.. I need to take each seq nbr from the input file ,run the query below: select ackname,seqnbr from event where event_text like '%seqnbr( from the input file)' and redirect the... (11 Replies)
Discussion started by: rkrish
11 Replies

4. Shell Programming and Scripting

Shell script for to view all users & groups history in root

Dear All, I want to know all users & group history in one file, for root terminal through shell or any other option (5 Replies)
Discussion started by: kpoobathi
5 Replies

5. Shell Programming and Scripting

Issue running script as root

1) Environment:Red Hat Linux, bash shell Script to be run owned by user :myUser Home environment of myUser: pathto/home 2) ESP agent with root access will run JobXXX.sh su - myUser -c "/pathto/home/bin/script.sh" where script.sh has some echo statements and an exit statement in the end... (4 Replies)
Discussion started by: cj09
4 Replies

6. Shell Programming and Scripting

Running a script from if block inside another script

how do i run a script from if block inside another script? this is what i tried but it doesnt seem to work: if test $a -eq $w then sh /home/scripts/script1.bash fi (3 Replies)
Discussion started by: shishirkotkar
3 Replies

7. Shell Programming and Scripting

Running a unix script(which is calling another script inside that) in background

Hi all, I am having a script ScriptA which is calling a script ScriptB in the same server and copying files to second server and have to execute one script ScriptC in the second server. THis First script ScriptA is the main script and i have to execute this process continously. for Keeping... (2 Replies)
Discussion started by: rohithji
2 Replies

8. Cybersecurity

Running script through SSH as root

Hi all, I have a situation where I have a shell script that I need to run remotely on multiple *nix machines via SSH. Unfortunately, some of the commands in it require root access. I know that best practices for ssh entail configuring it so that the root account cannot log in, you need to... (4 Replies)
Discussion started by: irinotecan
4 Replies

9. UNIX for Dummies Questions & Answers

running sed inside script file

i am substituting some text in the xml file using sed, on shell directly it works fine, but when i run it inside script file, it say, the function cant be parsed, i think the prob is due to xml file, kindly help (4 Replies)
Discussion started by: bajaj111
4 Replies

10. Shell Programming and Scripting

Running a command or script as root

I'm writing an application (Progress language) that needs to: 1) load the contents of a cron table into the Progress application; 2) display this information in a human manner and allow a select group of people to update it (these people are logged in as themselves, not as root); 3) save... (3 Replies)
Discussion started by: rm-r
3 Replies
Login or Register to Ask a Question