NFS share bash script issue

Soldato
Joined
18 May 2010
Posts
22,879
Location
London
I'm working on a backup script for my satellite server.

Red Hat provide a script which I have modified.

My issue is the following.

The script will run as root (I suppose)

I need to mount and unmount an nfs share.

Then sudo su to a user that has write permissions (nfsuser) on the share then run the satellite-backup command then exit as nfsuser back to root and umount the nfs share.

The problem is the satellite-backup command seems to need to run as root, but at this point I am currently in as nfsuser:

#!/bin/bash -e
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESTINATION=/backups/satellite_backup
YEAR=$(date +%Y)
WEEK=$(date +%-V)

mount nfsshareserver:/backup /backups
sudo su nfsuser

if [[ $(date +%w) == 0 ]]; then
satellite-backup $DESTINATION/$YEAR-$((WEEK + 1)) --assumeyes
else
LAST=$(ls -td -- $DESTINATION/$YEAR-$WEEK/*/ | head -n 1)
satellite-backup $DESTINATION/$YEAR-$WEEK --incremental "$LAST" --assumeyes
fi
exit 0

exit
umount /backups

How do I make the satellte-backup command run as root. The issue is only the nfsuser can write to the nfs share.
 
Last edited:
I think this would work:

sudo su root -c 'satellite-backup $DESTINATION/$YEAR-$((WEEK + 1)) --assumeyes'

That'd run that command as root and then drop back to the nfsuser. You'd need to edit the second satellite-backup command too of course.

I'll try it tomorrow.

However isn't the problem that the nfsuser doesn't have privileges to sudo su root?
 
Back
Top Bottom