At 9:10 AM -0400 2007/10/26, Rich wrote:
Hi folks.
Just wondering how I get into superuser (sudo or su) using a shell
script. I am trying to back up the following to a folder on my
desktop:
/usr/local/mysql/*
/etc/httpd/httpd.conf
/etc/httpd/users/*
Given the unique permissions on this, my shell script has to run as
superuser. I tried this:
sudo;
"sudo" requires an argument; to get a root shell, use "sudo
-s". But sudo normally prompts for the password of the administrative
user running sudo, which is going to be a problem for a shell script.
You can run the script as root.
You can configure sudo not to require a password: "visudo" or
perhaps "sudo visudo" from the command line; then add "Defaults
!authenticate" at the top of the file.
Probably better to do something like this in a shell script
(which should be owned by root, not yourself, for security reasons;
don't put trailing slashes on the source directories or cp will
misbehave):
/usr/local/bin/backup-web.sh:
#!/bin/sh
$TODAY=date "+%Y-%m-%d"
mkdir -p ~rich/Desktop/backup/$TODAY
cp -R /usr/local/mysql /etc/httpd/httpd.conf /etc/httpd/users
~rich/Desktop/backup/$TODAY
chown -R rich ~rich/Desktop/backup/$TODAY
Then add a cron job for root: "sudo EDITOR=bbedit crontab -e"
and add an entry like this:
0 1 * * * /usr/local/bin/backup-web.sh
Chris
--
Chris Pepper: <http://www.reppep.com/~pepper/>
<http://www.extrapepperoni.com/>
The Rockefeller University: <http://www.rockefeller.edu/>
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>