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

LVL 2
k_suchdevaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ahoffmannCommented:
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.
k_suchdevaAuthor Commented:
>>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

k_suchdevaAuthor Commented:
>>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

C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

ahoffmannCommented:
> 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?
k_suchdevaAuthor Commented:
>>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

k_suchdevaAuthor Commented:
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.
ahoffmannCommented:
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
k_suchdevaAuthor Commented:
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.
k_suchdevaAuthor Commented:
Why it posts all my comments twice.
I got it now.

WIll get back to you after i try that.
k_suchdevaAuthor Commented:
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.
k_suchdevaAuthor Commented:
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.
ahoffmannCommented:
su - userX ....
k_suchdevaAuthor Commented:
nope it is syntactically wrong
i tried that already
ahoffmannCommented:
could you please post the message
HaynesSCommented:
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
k_suchdevaAuthor Commented:
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

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

Stephen
ahoffmannCommented:
Khem, you have to reject a proposed answer, then you can accept another comment as answer.
HaynesSCommented:
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.

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

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

Thanks

Computer101
E-E Moderator
ahoffmannCommented:
Khem,
- there are guidlines, somewhere at EE (sorry cannot remember the link)
- a questioner can always reject an answer (except the button is missing, 'cause EE does a lot of bugfixes at the moment:)
- there is no "automatic" way to stop someone getting answers and not awarding points, just som EE Moderators do remind them
- splitting points have to be done by EE Moderators, except you're willing to simply post a new "Points for EE_user" question

And keep in mind that EE people are busy, always, anyhow ...

Hope this helps to get used to EE ;-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ahoffmannCommented:
just to avoid confuision of future readers:
the answer can be founf in my 1'st and 2'nd comment (not the graded answer;-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.