precompressing and ownership


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers precompressing and ownership
# 1  
Old 08-14-2008
precompressing and ownership

I'm looking for a way to create preprocessed .gz files of static pages to serve up to those browsers that can accept them.

I know I can use:
gzip -c --best index.html > index.html.gz

to create the .gz file _and_ keep the original.

What's the proper command line way to run that on each index.html file in all the subdirectories? There's a way via find and/or xargs, right? Can it be done from the command line, or do I need a script?

Also, if I run the cron as a user other than root (i.e. my apache user) will the resulting gzip be owned by apache or do I have to chown it?

Thanks for any advice!
# 2  
Old 08-14-2008
Scripts are just canned command lines; if you can run it from the command line, you can put it in a script, and vice versa.

I believe gzip will preserve ownership of files but you can't use the -c option and redirection then. Of course, the user running the script will need write access to the files and directories you want to modify in any event.

Code:
find /path/to/var/www/html-docs/whatever -name 'index.html' -exec gzip -9 {} \;

To keep the originals as well, something a bit more complex is called for. The new files will be owned by the user who created them, and their permissions will be controlled by the user's umask.

Code:
find /path/to/var/www/html-docs/whatever -name 'index.html' -print |
xargs -n 1 -i sh -c 'gzip -c -9 < {} >{}.gz'

The sh is needed here because that's what handles redirection. Equivalently, you could create put those commands in a small script, and run that from xargs or find -exec on each file in turn. Here's an example.

Code:
#!/bin/sh
gzip -c -9 <"$1" >"$1".gz

Here's a slightly more elaborate script which handles multiple files and sets the permissions and ownership of the new files. Still, you could put those same commands in the arguments to sh -c if you don't want to create a physical script file for some reason.

Code:
#!/bin/sh
for f; do
  gzip -c -9 <"$f" >"$f".gz
  chmod 644 "$f".gz
  chown www-data:www-data "$f".gz
done

Now if you had saved this in $HOME/zipper (and chmod +x of course) you could run

Code:
find /path/to/var/www/html-docs/whatever -name 'index.html' -print | xargs $HOME/zipper


Last edited by era; 08-14-2008 at 03:38 AM.. Reason: Noticed you want to keep the originals; add sample script for calling from xargs
# 3  
Old 08-14-2008
Thank you so much! It worked great.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ownership changes

I have 2 Linux servers and 1 windows server. One Linux server has an NSF share which points to the windows server. The other Linux server rsyncs any data to the other Linux server containing the windows share. My issue is that everytime the Linux administrator rsync data to the linux server... (12 Replies)
Discussion started by: Lace0047
12 Replies

2. UNIX for Advanced & Expert Users

retain ownership

Hi, I have a script which transfers files/directories from one HP unix to another HP unix server using SCP but i need to retain ownership of files/folders same as source server my script is as follows cd /sasdata/TR_CNTO328/C0328T07/Dry_Run_1/Macros find . -type d -newer . -exec scp -pr {}... (6 Replies)
Discussion started by: tushar_spatil
6 Replies

3. UNIX for Dummies Questions & Answers

regarding changing ownership and group

i am able to change the mode using chmod and able to change permission. but i am not able to change group and ownership. getting as invalid can any one help me regarding this . (4 Replies)
Discussion started by: satheeshkr_cse
4 Replies

4. Shell Programming and Scripting

Get ownership info from LS

Hi, When I do the ls-ld command for example like this: # ls -ld /Applications I get an output like this: drwxrwxr-x+ 114 root admin 3876 18 Aug 14:04 /Applications I need to somehow use sed to put the ownership into a format like this: root:admin So basically remove... (2 Replies)
Discussion started by: pcwiz
2 Replies

5. UNIX for Dummies Questions & Answers

Ownership question

Hi there, Complete Newbie here so any help would be so appreciated! :) I've set up a test directory and am trying to figure out out how to ensure that all new files will remain owned by the directory owner... not the creator of the file?? (3 Replies)
Discussion started by: CasperQuiet
3 Replies

6. UNIX for Dummies Questions & Answers

changing ownership?

how would i change ownership of file1 so the user NATE gets ownership of the file? (1 Reply)
Discussion started by: trob
1 Replies

7. Shell Programming and Scripting

Why the cp keeps the original ownership?

I want to copy a file from another user to my owner directory, and want to change the ownership to my account. in jung's directory: -rwxr-xr-x 1 jung smart 23 Dec 1 2005 .runme cp /home/jung/runme . under my directory: -rwxr-xr-x 1 jung smart 23 Dec 1... (1 Reply)
Discussion started by: freelong
1 Replies

8. Solaris

Filesystem ownership with zones

What I have" Solaris 10 U4, recently patched. ZFS filesystems on the global zone Local Zones on the zfs filesystems. If I make a new ZFS filesystem, and present it to a local zone, i.e. /u01. If I change the ownership of /u01 in the Local zone to oracle:dba /u01. The file becomes... (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

9. Shell Programming and Scripting

help regarding file ownership

hi friends,i have a doubt,if there is a file for which i have only read access then is there any way to execute it,plz reply soon (5 Replies)
Discussion started by: amit007
5 Replies

10. UNIX for Dummies Questions & Answers

ownership of files

Hi, While changing ownerships from the root on a server i'm managing, i typed chown -R username:users * and it changed all ownership to username. Can someone tell me if there is someway I can set things back the way they were before? I can't even su username from the root. Am I going to just... (4 Replies)
Discussion started by: szhu
4 Replies
Login or Register to Ask a Question