Thanks for all the great responses so far. Wow, that was fast. Let me
provide a little more light so maybe I can "help you help me." :-)

I have a homemade script (my first /real/ shell script), backup.sh, owned
by root, located in /root/bin. It copies all the files in
/home/dave/public_html, dumps some MySQL data, tars it all up and stores
it in /home/dave/backups as a tar.gz with the date in the name.
Eventually, this will run as a daily cron job. I'd like the script to run
as user dave just to be safe. If I put

su dave

near the top of the script, it stops execution there, likely because it
logs into the 'dave' account and never gets on with the rest of the
script. Notice that I didn't put 'su - dave', but that fails also, dumping
me to dave's bash shell, and when I logout (ctrl+d), it continues.

I guess I have a couple (4) options:

1. Write a C program called become_dave that simply does:

int main() {
  setuid( 500 );
  setgid( 500 );
}

and call that from backup.sh instead of 'su dave'. Not sure if that'll
really work.

2. In my /etc/crontab, specify 'dave' as the user to run the script as.

3. Use PHP and save myself a whole ton of hassle (sporting the setuid()
and setgid() functions natively like Perl. PHP rocks for sysadmining).

4. Use csh where setuid() is also available.

What would you all recommend? Seems to me like option 2 is bad since I'd
like to 'chmod 700 backup.sh' to prevent non-root users from running it.

--Dave


<quote who="Andrew Jorgensen">
> I'm not sure just how, but I'll bet you need expect here. expect lets
> you control input to any program and respond appropriately to it's
> output, all in a script.
>
> Why won't su work? (I'm not saying it does, I'm just curious.)
>
> David Smith wrote:
>> I'd like to be Borne Again in a script running as root. How can I
>> change to a different user (su won't work) during execution, like
>> setuid(int) does in C?
>>
>> --Dave



____________________
BYU Unix Users Group 
http://uug.byu.edu/ 
___________________________________________________________________
List Info: http://phantom.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to