4

I use an expect script to automate transfer of some support files onto terminals. The support files are automatically tarballed before being scp'ed onto the target terminal. This is accomplished by an in-house expect program that automatically fills out the password for the scp so we don't have to put the password in. I can copy the individual files without issue, but when I try to copy the tar.gz file, it changes the permissions of the /tmp directory. I have been chmodding the /tmp directory back to 1777 for the permissions and chowning it to root.root, which is how it is normally set up, but this doesn't always work. It is causing sqlite errors due to sqlite not being able to write a temp file to /tmp, which is very disruptive. How can I determine the exact cause of this? I know it has to be related to the tar.gz file, but I was under the impression that tar would preserve the permissions on the file.

the permissions on the file inside my directory are:

-rw-rw-r-- 1 aembree aembree  88K Oct  2 15:20 dropin.tar.gz

Before the transfer /tmp looks like this in an ls -al:

drwxrwxrwt  15 root root 8.4K Oct  2 15:08 tmp

After the transfer /tmp looks like this:

drwxrwxr-x  15 10539 10539 8.4K Oct  2 15:01 tmp

The tar command being run is the following:

tar -vPczf /home/aembree/bin/resources/dev/dropin.tar.gz --exclude='helperscript' -C $dropinlist . > /home/aembree/bin/resources/logs/tarlog

Once the file is on the remote machine, expect executes the following command to unpack it:

send "cd /tmp ; tar -xzf dropin.tar.gz ; rm dropin.tar.gz ; cd ;\n"
6
  • Can you share the expect script? or at least the exact tar and scp commands executed?
    – zuazo
    Oct 2, 2016 at 19:19
  • I cannot access the source of the expect script that does the transfer, it is hidden away somewhere that makes me think I'm not supposed to be able to see it :/ I will add the tar command being run to the op Oct 2, 2016 at 19:24
  • As scp never does it, the problem is in the script. Oct 2, 2016 at 19:28
  • and yet that script only has trouble with my archive file. it never changes permissions of /tmp when transferring any other file Oct 2, 2016 at 19:32
  • I bet your tarball was created from ./ so when it is extracted it overrides the current directory's (./) permissions.
    – jsbillings
    Oct 2, 2016 at 19:33

1 Answer 1

7

You've included . in your source collection given to tar. The problem occurs when you extract the tarball and the permissions are applied. Your source directory . is extracted and permissions applied. Unfortunately at the point of extraction . is actually /tmp.

The fix is either to exclude . from the tarball or to create a temporary directory within /tmp in which to extract it all.

2
  • this appears to be the correct answer. I changed my tar command to tar -czvf /home/aembree/bin/resources/dev/dropin.tar.gz --directory="/home/aembree/bin/resources/dropins" $dropinlist > /home/aembree/bin/resources/logs/tarlog and it no longer changes permissions on /tmp when transferred in. Thanks a bunch! Oct 2, 2016 at 20:00
  • @AbbyEmbree if this answer works for you please remember to tick it to show this
    – roaima
    Oct 2, 2016 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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