LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-15-2012, 06:51 AM   #1
rainjam
LQ Newbie
 
Registered: Jun 2012
Posts: 7

Rep: Reputation: Disabled
Running a script as a different user from crontab


I've got a backup script which runs every night from crontab. It copies a load of folders from various parts of a server (a Qnap TS-809, so not a full-fat distro of Linux) into a folder called BACKUP, compresses them, then rsync's these to a remote server. One of the first things it has to do is remove the previous night's folders from BACKUP, because I want to start fresh each night (ie not merge with anything that has since been deleted). So I have the dreaded command:

Code:
rm -r /share/Somefolder/BACKUP/share/
(/share is the root folder, and I'm copying folders into BACKUP with their --parents to preserve file paths and avoid collisions)

Obviously, this is a dicey way to do it, as (I'm guessing?) the script currently runs as root. I've created a special user for backups, and the ideal thing would be that it can only delete folders it created, so in the unlikely event that the script got altered to be, for example,

Code:
rm -r /*
or something, only the folders that the backup user had created by copying them would be wiped.

(I'm kind of guessing my way here, so please correct me if I'm wrong on any of this!)

I can "su" to the backup user if I'm in a shell, but is there a way to execute the rm and copy commands as the backup user, so the folders are locked down a bit?

Thanks in advance!
 
Old 06-15-2012, 07:06 AM   #2
rosehosting.com
Member
 
Registered: Jun 2012
Location: Missouri, USA
Posts: 236

Rep: Reputation: 64
Quote:
Originally Posted by rainjam View Post
is there a way to execute the rm and copy commands as the backup user, so the folders are locked down a bit?

Thanks in advance!
You could use:

Code:
su - testuser -c "whoami"
so it will return testuser.

hope that helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Crontab not running script j8177e5 Linux - Newbie 2 12-21-2010 08:54 AM
[SOLVED] Crontab Script Not Running th1bill Ubuntu 4 12-10-2010 03:49 PM
crontab not running script sunlinux Linux - Newbie 5 05-18-2010 06:21 AM
Shell Script not Running from Crontab venkatramanj SUSE / openSUSE 3 01-13-2010 05:15 AM
Running a script with crontab. glore2002 Slackware 3 06-05-2008 08:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration