The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
100% ownership to files Terrible UNIX for Dummies Questions & Answers 3 12-05-2006 10:40 AM
Losing ownership with gzip superdelic UNIX for Dummies Questions & Answers 3 07-24-2006 08:36 AM
help regarding file ownership amit007 Shell Programming and Scripting 5 09-07-2005 02:42 AM
ownership of files szhu UNIX for Dummies Questions & Answers 4 12-31-2003 09:59 AM
Preserving Ownership w/tar bergerj3 Filesystems, Disks and Memory 1 02-05-2002 08:53 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-13-2008
Registered User
 

Join Date: Aug 2008
Posts: 2
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!
Reply With Quote
Forum Sponsor
  #2  
Old 08-13-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
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-13-2008 at 11:38 PM. Reason: Noticed you want to keep the originals; add sample script for calling from xargs
Reply With Quote
  #3  
Old 08-13-2008
Registered User
 

Join Date: Aug 2008
Posts: 2
Thank you so much! It worked great.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0