[NTLUG:Discuss] Bash Scripting and permissions

kbrannen@gte.net kbrannen at gte.net
Sat Nov 30 10:41:18 CST 2002


Patrick Parks wrote:
> I am working on a simple bash script, that will tar and zip my home dir 
> onto a remote backup computer across nfs. On the backup computer in the
> /etc/exports file the permissions for the share that is exported to nfs
> is using the defaults, the root_squash. I would like to keep this as is
> if possible, for security. Now back to my script. My script checks to
> see if the directory is mounted before trying to tar then zip the file
> to it.If it is not mounted, it then attempts to mount it. This is where
> the problem comes in. In order to mount the nfs directory, I must be
> root. If I run the script as root, when it gets to the part about
> copying the files to the remote mounted nfs drive, it does not let me
> copy, cause I am root, and the root_squash is on   in the exports
> permissions. As I am writing this I am getting some ideas :) Can a user
> have permissions to mount a remote nfs directory without having to sudo?
> That may be my answer there, off to the search engines to see if this
> will work, would appreciate any suggestions. Thanks

Use 2 scripts (programs).  Have 1 program that all it does is [un]mount the 
NFS dir, and the other script to do all the other work.  Something like this:

#!/bin/bash
# mount as root
/usr/local/bin/mountnfs /backup
# backup
tar -czvf /backup/`date`.tgz /home
# unmount as root
/usr/local/bin/mountnfs -u /backup

So the script above is the controlling script and makes the calls to the other 
program to do the "special" work; and the mountnfs script you write should be 
able to do nothing other than mount and umount (or you could use sudo as you 
imply).

HTH,
Kevin





More information about the Discuss mailing list