Solved

Restart Scripts

Posted on 2002-06-10
22
231 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
Comment Utility
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
Comment Utility
>>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
Comment Utility
>>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
Comment Utility
> 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
Comment Utility
>>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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
su - userX ....
0
 
LVL 2

Author Comment

by:k_suchdeva
Comment Utility
nope it is syntactically wrong
i tried that already
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
could you please post the message
0
 

Expert Comment

by:HaynesS
Comment Utility
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
Comment Utility
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
Comment Utility
Khem,
   I have tried to take back, but unable to. Sorry.

Stephen
0
 
LVL 51

Expert Comment

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

Expert Comment

by:HaynesS
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
create user in TSM 7 551
sudo logging 5 64
AIX  NFS  question 1 98
how to check for shares on aix 1 50
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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 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.:

772 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

10 Experts available now in Live!

Get 1:1 Help Now