Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-15-2012, 07:51 AM   #1
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:

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,

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, 08:06 AM   #2
Registered: Jun 2012
Location: Missouri, USA
Posts: 223

Rep: Reputation: 62
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:

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

hope that helps.


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 09:54 AM
[SOLVED] Crontab Script Not Running th1bill Ubuntu 4 12-10-2010 04:49 PM
crontab not running script sunlinux Linux - Newbie 5 05-18-2010 07:21 AM
Shell Script not Running from Crontab venkatramanj SUSE / openSUSE 3 01-13-2010 06:15 AM
Running a script with crontab. glore2002 Slackware 3 06-05-2008 09:48 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:59 PM.

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