Tarring problem.

We execute script to tarr files as normal user. Normal user doesn't have permission to append file to existing tarr file, since tarr files are owned by root user.

Even though script is creating tar file and is executed by normal user, It shows that tar file is created by root. I ran script for the date range 13-SEP-2011 and 14-SEP-2011. File tarring listed all files for the date 13-SEP-2011 first and tarred it and listed all the files belongs to 14-SEP-2011 then it tried to append these files to existing tarr file since both dates belong to the same week.Since normal user did not has enough permission to change the permission of the tarr file. Hence error occurred.

Example: Say, there are three files present in test directory namely a.txt, b.txt, c.txt and all are owned by root and belons to different week.
tar cvf TarFilename a.txt --> Working as expected.
The above script creates tarr file which is owned by root. since tarr fie retains propreties of file got tarred.
chmod 777 TarFilename
tar -rf TarFilename b.txt --> Failing since normal user does not has the permission to change the permission of tarr file.

We have two options now.

  1. Change the owner of the directory where files need to be tarred.
  2. Change the owner of the files(a.txt,b.txt etc) before sending it to our database.

Is there any way that we can achive this apart from above cases. please let me know.

Please let me know if need any details.

Thanks and Regards
Nagaraja

You can confiure sudoers to do the job.

sudo tar -rf TarFileName b.txt

The above command will run with root permissions.

You will have to add the following line in the /etc/sudoers file

normal_user ALL=NOPASSWD : /usr/bin/tar

--ahamed

1 Like

Allowing tar to be run as root is a big security hole, I'd advise against that.

Funny thing is I can't get tar to change owner of .tar file as you describe. What OS are you running and can you supply output of:

tar --version
what `which tar`
1 Like

Ahamed,

Thanks for your answer. I will check this option.

Chubler,

tar -V 

gives below results.

 
tar: option requires an argument -- V
Try `tar --help' for more information
what `which tar`

gives below output.

-bash: what: command not found

 which tar 

gives output as below.

/bin/tar

Please let me know if it is helpful to you.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The version of the tarris 1.14. Typed man tar and at the end I got this version. In latest version

tar -V, what `which tar` 

gives the version.