[comp.unix.questions] starting a process as another user during startup

coleman@cam.nist.gov (Sean Sheridan Coleman X5672) (05/15/91)

I have a shell script currently that cron runs as a user
called nbsnet which starts up a monitoring program and is 
left to run throughout the day. At the end of the day, this 
user's cron will kill the process and do some work with the
data it received. 

I take the machine down once a month for backups, etc but
this process is never restarted ( I have reset it in cron now)

What I would like to do is have the rc.local run this script
and start up this monitoring program as a part of its startup 
but I want it to start the process so the user is nbsnet not
root. Is there a way to do this and if so, how?


Your assistance is appreciated. Without the net, my job would
be twice as hard.

coleman@bldrdoc.gov
Sean Coleman
NIST
Boulder, CO

les@chinet.chi.il.us (Leslie Mikesell) (05/16/91)

In article <8646@alpha.cam.nist.gov> coleman@cam.nist.gov (Sean Sheridan Coleman X5672) writes:

>What I would like to do is have the rc.local run this script
>and start up this monitoring program as a part of its startup 
>but I want it to start the process so the user is nbsnet not
>root. Is there a way to do this and if so, how?

Use:
 su -c user "command string"

My (AT&T sysV) man page gives very little information about this form
but as I recall, it runs the users shell as per the passwd file as well
as using the uid, and if that shell is ksh, it will execute the user's
.profile, where sh will not (watch out for interactive commands!).

I prefer to let init respawn this kind of program, since it can then
exit under whatever conditions you want and a new copy will always
restart, and a screw-up like an interactive prompt won't hang the
machine like it does in the rc.d files.  You probably only want it
at run-level 2 and 3 anyway.

Les Mikesell
  les@chinet.chi.il.us

urban@cbnewsl.att.com (john.urban) (05/16/91)

In article <8646@alpha.cam.nist.gov> coleman@cam.nist.gov (Sean Sheridan Coleman X5672) writes:
> DELETED STUFF
>
>What I would like to do is have the rc.local run this script
>and start up this monitoring program as a part of its startup 
>but I want it to start the process so the user is nbsnet not
>root. Is there a way to do this and if so, how?
>
>

Try:
	su nbsnet -c "This command to run"

Since you're running as root, the su(1) command will not prompt you for the password.

Sincerely,

John Ben Urban

toma@swsrv1.cirr.com (Tom Armistead) (05/17/91)

In article <8646@alpha.cam.nist.gov> coleman@cam.nist.gov (Sean Sheridan Coleman X5672) writes:
>I have a shell script currently that cron runs as a user
>called nbsnet which starts up a monitoring program and is 
>left to run throughout the day. At the end of the day, this 
>user's cron will kill the process and do some work with the
>data it received. 
>
>I take the machine down once a month for backups, etc but
>this process is never restarted ( I have reset it in cron now)
>
>What I would like to do is have the rc.local run this script
>and start up this monitoring program as a part of its startup 
>but I want it to start the process so the user is nbsnet not
>root. Is there a way to do this and if so, how?
>
>
>Your assistance is appreciated. Without the net, my job would
>be twice as hard.
>
>coleman@bldrdoc.gov
>Sean Coleman
>NIST
>Boulder, CO

Put 'su nbset -c command' in you startup script...

Tom
-- 
Tom Armistead - Software Services - 2918 Dukeswood Dr. - Garland, Tx  75040
===========================================================================
toma@swsrv1.cirr.com                {egsner,letni,ozdaltx,void}!swsrv1!toma

det@nightowl.MN.ORG (Derek E. Terveer) (05/18/91)

les@chinet.chi.il.us (Leslie Mikesell) writes:

>In article <8646@alpha.cam.nist.gov> coleman@cam.nist.gov (Sean Sheridan Coleman X5672) writes:

>>but I want it to start the process so the user is nbsnet not
>>root. Is there a way to do this and if so, how?

> su -c user "command string"

I believe that you meant	su user -c "command string"
In your form (at least on the systems that i have access to), su will see the
"-" argument and "redo" the environment...
-- 
det@nightowl.mn.org

jpr@jpradley.jpr.com (Jean-Pierre Radley) (05/23/91)

In article <8646@alpha.cam.nist.gov> coleman@cam.nist.gov (Sean Sheridan Coleman X5672) writes:
>I have a shell script currently that cron runs as a user
>called nbsnet which starts up a monitoring program and is 
>left to run throughout the day. At the end of the day, this 
>user's cron will kill the process and do some work with the
>data it received. 
>
>I take the machine down once a month for backups, etc but
>this process is never restarted ( I have reset it in cron now)
>
>What I would like to do is have the rc.local run this script
>and start up this monitoring program as a part of its startup 
>but I want it to start the process so the user is nbsnet not
>root. Is there a way to do this and if so, how?

su nbsnet -c "your_script and arguments thereto"

Jean-Pierre Radley   Unix in NYC   jpr@jpr.com   jpradley!jpr   CIS: 72160,1341