LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-20-2011, 07:08 AM   #1
hen770
Member
 
Registered: Oct 2010
Distribution: Arch
Posts: 136

Rep: Reputation: 7
user crontab, needs root privileges ?!


Hi,

i know the subject is hard to understand but i did my best with it.

the problem:

i have 2 HDs on my Ubuntu OS, the first is 1TB and the other is 500GB, i want to do a backup with rsync from my 1TB HDs (in with the Ubuntu is on it) to the 500GB.

on the 500GB i have a partition called Backup.

what i did:

i have created a user crontab that dose two things:
1. mount the Backup partition from the 500GB to a folder called /~/Backup on my home directory which is on the 1TB HD.

2. i wrote the proper rsync command for the backup to go.


that is my crontab, ('hanan' is the username):

Code:
SHELL=/bin/bash
MAILTO=hanan
33 3    * * * /bin/mount /dev/sdb2
34 3    * * * /usr/bin/rsync -r -t -v --progress --delete --size-only /home/hanan/Programs/Stuff/Printers/ /home/hanan/Backup/
the problem:

when the time for the crontab comes it mounts the Backup partition to the right location on the user's home directory, but it can't do the second step because it needs root privileges in order to write on the mounted HD.

i have tried that manually and still i can't copy any file to the mounted HD unless i do it with the sudo command.

am i missing something ?

i want to that via the CLI and cron just for the study experience.

thanks.
 
Old 03-20-2011, 07:42 AM   #2
hen770
Member
 
Registered: Oct 2010
Distribution: Arch
Posts: 136

Original Poster
Rep: Reputation: 7
here is some more info about it:

i have an entry in my /etc/fstab file like that:

/dev/sdb2 ~/Backup ext4 defaults,noauto,users 0 0


i am able to mount it without the sudo command, but i can't write to the mounted HD.

that is:
before i mount the HD, the folder Backup on my home folder had the following permissions:
Code:
drwxr-xr-x 3 hanan hanan 4096 2011-03-20 03:23 Backup
and after i mount it (via the crontab, or manually without sudo), it become like that:
Code:
drwxr-xr-x 2 root root 4096 2011-03-20 03:21 Backup
here i think the problem is hide, why it is the directory become the root owner ?!
 
Old 03-20-2011, 08:09 AM   #3
ongte
Member
 
Registered: Jun 2009
Location: Penang, Malaysia
Distribution: Mageia, CentOS, Ubuntu
Posts: 468

Rep: Reputation: 72
You should change the owner after you've mounted the partition. All you need to do now is mount the partition & run chown to change the owner to yourself.
Quote:
$ sudo chown hanan.hanan Backup
You only need to do this once & it should be working after that.

Explanation:
Since you partition was formated by root (using sudo), the filesystem that was created is naturally also owned by root. You have to mount the partition & manually change the owner. This goes for all filesystems that understand UNIX permissions (ext2/3/4,reiserfs,btrfs). This does not apply to non-UNIX filesystems like vfat/ntfs, where the owner/permission is specified during mount, udev or fstab.

Last edited by ongte; 03-20-2011 at 08:15 AM.
 
1 members found this post helpful.
Old 03-21-2011, 03:15 AM   #4
hen770
Member
 
Registered: Oct 2010
Distribution: Arch
Posts: 136

Original Poster
Rep: Reputation: 7
Thank you !

i have 2 options now, what is the best method:

1. to change the permissions to 777 and still leave it by the owner of root.
2. change the owner to my name.

.
 
Old 03-21-2011, 09:08 AM   #5
ongte
Member
 
Registered: Jun 2009
Location: Penang, Malaysia
Distribution: Mageia, CentOS, Ubuntu
Posts: 468

Rep: Reputation: 72
If you are the only user on this computer, there's no reason not to change the owner. If not, you can always change both.
 
  


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
Giving root privileges to another user BlackJackal Mandriva 5 10-19-2005 01:03 PM
How to give user always root privileges? SimeonV SUSE / openSUSE 18 06-23-2005 11:02 AM
Root privileges for user ar1 Linux - Security 2 01-07-2005 09:33 PM
User with root privileges ShakyJake Linux - Newbie 2 06-18-2004 12:12 PM
Giving a User Root Privileges lawrencegoodman Linux - Newbie 4 12-23-2003 04:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:46 PM.

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