[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cobalt-users] O/T copying files in linux
- Subject: Re: [cobalt-users] O/T copying files in linux
- From: "Steve Werby" <steve-lists@xxxxxxxxxxxx>
- Date: Wed Jun 19 18:49:01 2002
- List-id: Mailing list for users to share thoughts on Sun Cobalt products. <cobalt-users.list.cobalt.com>
"Tim Skipper" <mailinglists@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> I've got a cron job running that copies all the rotated logs from my
> various sites into one location for easy downloading. Here's an
> example of one line:
>
> cp /home/sites/site89/logs/web.log.1.gz
> /home/sitelogs/images-web.log.1.gz
>
> This works fine, but, the destination file assumes the file date/time
> of when the copy is performed. I want it to retain the original file
> date/time so I can easily see when a new rotations has occured by
> sorting in date order.
>
> How do I do this?
Hi, Tim. Use the -p flag. cp -p source destination. cp --help and man cp
for more info.
> Second question: Is there an easy way of writing a single cp command
> that will look through every virtual site and copy web.log.*.gz to
> another location and rename it sitename-web.log.*.gz ??
With a single cp command yes, but not without other commands mixed in.
Someone that writes bash scripts all day may be able to come up with
something more efficient, maybe even a one-liner which can be printed on a
black tshirt sold on thinkgeek, but here's what I put together. I didn't
test it, but I can do this kind of bash scripting in my head. Past the
following into a text file, make it executable by the desired user and add
to the user's cron. Enjoy.
#!/bin/sh
DESTINATION_DIR="/path_to_download_dir"
[ -d $DESTINATION_DIR ] || mkdir -r $DESTINATION_DIR
for SITE in `ls -1 /home/sites/ | grep -v site | grep -v home`
do
for WEB_LOG in `ls -1 /home/sites/$SITE/logs/ | grep web.log.*.gz`
do
cp -p /home/sites/$SITE/logs/$WEB_LOG
$DESTINATION_DIR/$SITE-$WEB_LOG
done
done
chown -R admin:admin $DESTINATION_DIR
--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/