[wplug] script help

Bill Moran wmoran at potentialtech.com
Fri Oct 31 09:21:17 EST 2003


Russ Schneider wrote:
> I have 2 hard drives on my machine.  One for linux, the other for windows.
> 
> Usually all I use the windows drive for is to back up files from my 
> linux drive.
> 
> I'd like to write a script and cron it so that it would run these 
> commands for copying the files every week or so in the middle of the 
> night, but some of the commands need to be run under different users. 
> Such as:
> 
> cp -Ruf /home /mnt/windows/backup/ (needs to be run as root)
> pg_dumpall > /mnt/windows/backup/file.sql (needs to be run as postgres)
> 
> et cetera....
> 
> If I were to write a simple BASH script to run these commands, how could 
> I get the commands to run as particular users?

Three pieces of information that can be useful:

First, the sudo program will allow you to easily run different program as
different users.  It's installed on most Linux distros these days, but if
it's missing from yours, it's probably worth installing.

Second, the _system_ crontab (not your user crontab) has the built-in
facility of running processes under different UIDs.  The distinction betweeen
user crontab and system crontab can be confusing (especially because root
can have a _user_ crontab that many people can confuse with the system
crontab).  On BSD systems, the system crontab is in /etc/crontab, while
the user crontabs are maintained with the crontab(1) command.  I don't
remember if this is the same for most Linux distros or not.

Third, the pg_dumpall command takes a -U option to determine what user it
runs as.  Most programs that require secondary authentication (such as
database clients, which is all pg_dumpall is) will have a switch to change
the user context.

Hope this information is useful and some combination of these solutions
works for you.

-- 
Bill Moran
Potential Technologies
http://www.potentialtech.com




More information about the wplug mailing list