Re: permission of script linked to cron
Haines Brown wrote:
I have a script, ~/scripts/backup, owned by root, that mounts an
external UPS drive, creates a directory based on date, and backs up my
hard disk with the exception of a few directories.
I created a symlink to /etc/cron.weekly to automate the job, but
because the script is located in user's directory, it runs with user's
permission, and much of the backup has "permission denied".
So I tried to start the script with this snippet:
which does not work. I have several questions:
a) Why does a script owned by root and run by root lack root's
permission just because it is in user's directory?
I am unable to reproduce this. Symbolic links in the /etc/cron.hourly
directory run as root irrespective of where the link points to. In my
case, the scripts were not even owned by root and were in a user's home
directory. Place a link to the following script and examine its output:
### Start of script
echo "UID=$UID; EUID=$EUID"
### End of script
In the snippet above the echo command is run _after_ the sudo command
completes. You probably wanted to pass the password to the standard
input of the sudo command. You can try using a pipe for that, like:
b) Why does the script snippet above not work?
echo $pw|sudo /path/to/your/backup-script
Note that depending on the manner in which sudo reads the password, the
above method might not work either.
c) How can I do what this script snippet intends without exposing my
plain text password?
see 'man sudoers' and allow your username to run the commands you want
without a password.