?
Solved

Restart Scripts

Posted on 2002-06-10
22
Medium Priority
?
238 Views
Last Modified: 2013-12-27
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

0
Comment
Question by:k_suchdeva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 8
  • 3
  • +1
22 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7067645
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.
0
 
LVL 2

Author Comment

by:k_suchdeva
ID: 7067700
>>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

0
 
LVL 2

Author Comment

by:k_suchdeva
ID: 7067734
>>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

0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 51

Expert Comment

by:ahoffmann
ID: 7067752
> 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?
0
 
LVL 2

Author Comment

by:k_suchdeva
ID: 7067757
>>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

0
 
LVL 2

Author Comment

by:k_suchdeva
ID: 7067781
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.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7067819
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
0
 
LVL 2

Author Comment

by:k_suchdeva
ID: 7067875
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.
0
 
LVL 2

Author Comment

by:k_suchdeva
ID: 7067890
Why it posts all my comments twice.
I got it now.

WIll get back to you after i try that.
0
 
LVL 2

Author Comment

by:k_suchdeva
ID: 7088769
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.
0
 
LVL 2

Author Comment

by:k_suchdeva
ID: 7088821
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.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7090073
su - userX ....
0
 
LVL 2

Author Comment

by:k_suchdeva
ID: 7090091
nope it is syntactically wrong
i tried that already
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7090135
could you please post the message
0
 

Expert Comment

by:HaynesS
ID: 7093347
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
0
 
LVL 2

Author Comment

by:k_suchdeva
ID: 7093397
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

0
 

Expert Comment

by:HaynesS
ID: 7109018
Khem,
   I have tried to take back, but unable to. Sorry.

Stephen
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7109039
Khem, you have to reject a proposed answer, then you can accept another comment as answer.
0
 

Expert Comment

by:HaynesS
ID: 7109109
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.
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7109121
Proposed answer rejected.  Would like like to award an expert or split points with other experts?

Thanks

Computer101
E-E Moderator
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 800 total points
ID: 7109972
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 ;-)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7110059
just to avoid confuision of future readers:
the answer can be founf in my 1'st and 2'nd comment (not the graded answer;-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question