Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have this bash script which outputs the first two files as owned by user, and the next three as owned by root:

##################################################
# Variables
NUM="6"     #number of backup files to keep
LOGFILE="/home/boudiccas/cron/obnam-ls.txt"
####################################################

# Change into new directory
cd /home/boudiccas/cron/obnam/

# Generate new file and save it
sudo -u boudiccas obnam ls>"obnamhome-ls-$(date +%Y-%m-%d).txt"

sudo -u boudiccas obnam --config=/etc/obnam-back4.conf ls>"obnamback4-ls-$(date +%Y-%m-%d).txt"

obnam --config=/etc/obnametc.conf ls>"obnametc-ls-$(date +%Y-%m-%d).txt"

obnam --config=/etc/obnamusr.conf ls>"obnamusr-ls-$(date +%Y-%m-%d).txt"

obnam --config=/etc/obnamvar.conf ls>"obnamvar-ls-$(date +%Y-%m-%d).txt"

# Delete old backups!
find /home/boudiccas/cron/obnam -type f -mtime +$NUM -name 'obnamhome-ls-*.txt' -exec rm -v {} + >>$LOGFILE 2>&1

find /home/boudiccas/cron/obnam -type f -mtime +$NUM -name 'obnamback4-ls-*.txt' -exec rm -v {} + >>$LOGFILE 2>&1

find /home/boudiccas/cron/obnam -type f -mtime +$NUM -name 'obnametc-ls-*.txt' -exec rm -v {} + >>$LOGFILE 2>&1

find /home/boudiccas/cron/obnam -type f -mtime +$NUM -name 'obnamusr-ls-*.txt' -exec rm -v {} + >>$LOGFILE 2>&1

find /home/boudiccas/cron/obnam -type f -mtime +$NUM -name 'obnamvar-ls-*.txt' -exec rm -v {} + >>$LOGFILE 2>&1
########################################################################

How can i get the last three files to be owned by user through the script please?

share|improve this question

1 Answer 1

To change ownership of a file, you can use chown, this way :

chown newuser myfile

or, if you want to change group as well :

chown newuser:newgroup myfile

In your case, you can also change your 3 last lines to add sudo -u boudiccas before obnam ..., it should do the trick.

share|improve this answer
    
Thanks, I know about chowning, but I'm really looking for something that can go in the script and be done automatically. –  boudiccas Jul 23 '13 at 13:36
4  
@user205787 and what is preventing from adding some chown commands in your script ? –  Levans Jul 23 '13 at 13:38
    
You were right Levans, chowning did all that I wanted, nice and simply and easily. Thanks. –  boudiccas Jul 23 '13 at 14:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.