Solved

Restart Scripts

Posted on 2002-06-10
22
232 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 200 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now