LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-08-2006, 01:49 PM   #1
spiffytech
Member
 
Registered: Dec 2005
Location: NC, USA
Distribution: (K)ubuntu
Posts: 139

Rep: Reputation: 15
Rotate and mail access logs


My webhosting company had a client request that we mail her the weekly access log. We created a script to do this, which also kept the past fopur weeks of logs.

Quote:
#!/bin/bash

LOGDIR="/var/log/httpd/www.continentalresources.com"
WORKDIR="/home/clients/client/www.client.com/htdocs/accesslog"

cd $WORKDIR

# Rotate the zip files save up to 4 weeks
# rm -f $WORKDIR/accesslog4.zip
# mv $WORKDIR/accesslogs3.zip $WORKDIR/accesslogs4.zip
# mv $WORKDIR/accesslogs2.zip $WORKDIR/accesslogs3.zip
# mv $WORKDIR/accesslogs.zip $WORKDIR/accesslogs2.zip

# Concatenate the access log files
# and put the day names in.
# Name the concatenated file "access.txt"
cat $LOGDIR/access_log.7 > access.txt
cat $LOGDIR/access_log.6 >> access.txt
cat $LOGDIR/access_log.5 >> access.txt
cat $LOGDIR/access_log.4 >> access.txt
cat $LOGDIR/access_log.3 >> access.txt
cat $LOGDIR/access_log.2 >> access.txt
cat $LOGDIR/access_log.1 >> access.txt

# Form the name
ZIPNAME="accesslog_"`date -d '7 days ago' +%Y%m%d`"-"`date -d '1 days ago' +%Y%m%d`".zip"

# Zip access.txt
zip -jq $ZIPNAME access.txt
rm -f access.txt

# Move the zip file to the ConRes
# document-root folder for web serving
# mv accesslogs.zip $WORKDIR

# Change the zip file permissions
# for web serving
chmod 2777 $WORKDIR/$ZIPNAME
chown client:ftp $ZIPNAME

# Send out a text file providing
# the download link for the last
# four (4) weeks of access files
sed 's/ZIPNAME/'$ZIPNAME'/' /opt/scripts/client_accesslog.txt | mail -s "Web Site Access Logs"
client_email_address
 
Old 02-09-2006, 09:25 AM   #2
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
Do you have a question or are you just sharing this information? Just as a side note there is software out there that does this called logrotate. I use it on my firewall machine and it works marvelously. You can give individual log files parameters as to how you would like to deal with them, for example you can mail the logs as well. I recommend giving this a shot.
 
Old 02-10-2006, 07:42 AM   #3
spiffytech
Member
 
Registered: Dec 2005
Location: NC, USA
Distribution: (K)ubuntu
Posts: 139

Original Poster
Rep: Reputation: 15
I was merely sharing my work. While writing scripts, I often wish that more people had written about what I'm trying to do, or that there was a script alreadyt out there, so I thought I'd help out anyone else who may need what I made.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rotate apache logs Berhanie Slackware 5 12-15-2004 09:36 PM
(also) Rotate Apache logs on-demand lothario Linux - Software 1 08-11-2004 07:21 PM
Server Mail Logs soulwatcher1974 Linux - Security 1 12-08-2003 11:35 PM
Mail logs Woutermelon Linux - Networking 2 11-21-2003 02:02 PM
mail logs when i havent sent mail poseidoniv Linux - Newbie 1 04-19-2003 02:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration