ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
# 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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.