Link to home
Start Free TrialLog in
Avatar of k_suchdeva
k_suchdeva

asked on

Restart Scripts

I have a machine with following configuration
SunOS XXXXXXXXXXX 5.7 Generic_106541-16 sun4u sparc SUNW,Ultra-80

I intent to put some restarts scripts in place so that i can start the processes that were running on the machine in case of a accidental shutdown.

I tried puttting stuff in in /etc/rc3.d but it does not seem to work.
I renamed the script to start with S but still no luck.

Can somebody advise whether this is the right approach ?

Also the scripts in /rc3.d will run with root privileges but i want to run the processes as some other user.

So for that if i do su - <login_name> in the script the next command in the script will not be run by the user it will be still run by root.

So please advise what is the most recommended approach that people tend to follow in these cases.

Thanks in advance.

Khem

Avatar of ahoffmann
ahoffmann
Flag of Germany image

the scripts in /etc/rc3.d must be named
   SnnANYNAME
   KnnANYNAME
where nn is a number: 00 .. 99
ANYNAME is any scriptname

The S* scripts are called when the systems enters runlevel 3 (for example with: init 3), the K* scripts are called when the system leaves runlevel 3. The S* scripts are called with the start parameter, the K* scripts with the stop parameter.
You may start these sripts at any time. This can be done by any user if this user has sufficent permissions to read and executes these scripts.
Avatar of k_suchdeva
k_suchdeva

ASKER

>>where nn is a number: 00 .. 99
>>ANYNAME is any scriptname

what does the number indicate and how does it matter.

>>Also the scripts in /rc3.d will run with root privileges >>but i want to run the processes as some other
>>user.
>>So for that if i do su - <login_name> in the script the >>next command in the script will not be run by
>>the user it will be still run by root.

Any inputs about that, i didn't really follow ur explanation about that.
How can i start the script with a user X by putting it in a the directory rc3.d/, they will always run as root user.

Thanks
Khem

>>where nn is a number: 00 .. 99
>>ANYNAME is any scriptname

what does the number indicate and how does it matter.

>>Also the scripts in /rc3.d will run with root privileges >>but i want to run the processes as some other
>>user.
>>So for that if i do su - <login_name> in the script the >>next command in the script will not be run by
>>the user it will be still run by root.

Any inputs about that, i didn't really follow ur explanation about that.
How can i start the script with a user X by putting it in a the directory rc3.d/, they will always run as root user.

Thanks
Khem

> what does the number indicate and how does it matter.
the scripts are called in ascending order of this number by init
So you need to take care if your script depends on others (like a web server depends on network, then the number for the network scriot must be lower to that of the web server script)

> How can i start the script with a user X by putting it in a the directory rc3.d/,
simply call the script when logged in as user X

> they will always run  as root user.
NO. they run as the user which called them. In fact that's root while booting.

Or do you mean that the scripts should run as user X while booting?
>>where nn is a number: 00 .. 99
>>ANYNAME is any scriptname

what does the number indicate and how does it matter.

>>Also the scripts in /rc3.d will run with root privileges >>but i want to run the processes as some other
>>user.
>>So for that if i do su - <login_name> in the script the >>next command in the script will not be run by
>>the user it will be still run by root.

Any inputs about that, i didn't really follow ur explanation about that.
How can i start the script with a user X by putting it in a the directory rc3.d/, they will always run as root user.

Thanks
Khem

I need the scripts to start some process for some user while startup.
While startup i won't be logged into the machine to run the scripts that's why they are boot up scripts.
So i want the scripts to run automatically when the machines boots.
I have the scripts, i know the user which should be used to run the scripts but i don't know how do i put it.
i hope this clarify my question.
build a simple script in /etc/rc3.d from the skeleton file there (or in /etc/init.d). In the 'start' section there call your special script with su. Fro example:

#! /bin/sh
case $1 in
  'start')
     su userX -c /path/to/your-script
     ;;
  'stop')
     ;;
esac
exit 0
I need the scripts to start some process for some user while startup.
While startup i won't be logged into the machine to run the scripts that's why they are boot up scripts.
So i want the scripts to run automatically when the machines boots.
I have the scripts, i know the user which should be used to run the scripts but i don't know how do i put it.
i hope this clarify my question.
Why it posts all my comments twice.
I got it now.

WIll get back to you after i try that.
when i do like that
su userX -c /path/to/your-script
it my env variables are not set because .profile is not being executed.

any switch which will force this command to execute .profile as well ?

i can always put .profile in my script but i am not considering that.
when i do like that
su userX -c /path/to/your-script
it my env variables are not set because .profile is not being executed.

any switch which will force this command to execute .profile as well ?

i can always put .profile in my script but i am not considering that.
su - userX ....
nope it is syntactically wrong
i tried that already
could you please post the message
Khem,
   Start by creating a file in the /etc/init.d directory and name it something; program1, for instance

   Next, create the structure in the file shown below

#!/sbin/sh
#
# Written by Stephen Haynes
# All rights reserved
#

Variable=value

case "$1" in
'start')
     if [ SOMETHING ]; then

          (Insert your startup line here)

     fi    
     ;;

'stop')

     if [ SOMETHING ]; then

          (Insert your shutdown line here)

     fi    
     ;;

*)
     echo "Usage: $0 { start | stop }"
     exit 1
     ;;
esac
exit 0


Create the following links:

cd /etc/rc0.d; ln -s /etc/init.d/program1 K98program1
cd /etc/rc1.d; ln -s /etc/init.d/program1 K98program1
cd /etc/rc2.d; ln -s /etc/init.d/program1 K98program1
cd /etc/rc3.d; ln -s /etc/init.d/program1 S98program1
cd /etc/rcS.d; ln -s /etc/init.d/program1 K98program1

The links above will ensure that your code will run while in Run Level 3 (default) and be terminated when switching to any other Run Level (nicely).

To run a command or script as another user, do this:

su - USER -c "script" &

The dash will execute the users profile, the -c will run the named script and the quotations may or may not be necessary (I run a few scripts as CRON jobs)

Cheers,
Stephen
Hi Stephen

Thanks for the detailed explanation.
I really appreciate that.
But you are a bit late for points.
All the information you provided is there in ahoffmann comments in bits and pieces.

So please take ur answer back so that i can accept ahoffman comments and answer.

Thanks and Regards
Khem

Khem,
   I have tried to take back, but unable to. Sorry.

Stephen
Khem, you have to reject a proposed answer, then you can accept another comment as answer.
Khem and ahoffman,
  I have asked a mediator to look into this.  Frankly, I am only a week into EE, and am suprised by the lack of guidelines on how to do this.  I can't believe that a questioner can reject an answer after having received it so easily.  What is to stop someone from getting the answer and awarding no points for it?  I am also curious as to the possibility of splitting points between commentors (if it is possible).  I have a question on the boards for the last week that has not been commented on, so I cannot see how that end of it works.

https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20316161

Here is a link to the question I posted in Community Support.
Proposed answer rejected.  Would like like to award an expert or split points with other experts?

Thanks

Computer101
E-E Moderator
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
just to avoid confuision of future readers:
the answer can be founf in my 1'st and 2'nd comment (not the graded answer;-)