<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RootAdmin.co.uk &#187; send logs daily</title>
	<atom:link href="http://rootadmin.co.uk/tag/send-logs-daily/feed/" rel="self" type="application/rss+xml" />
	<link>http://rootadmin.co.uk</link>
	<description>The Blog of Liam Somerville</description>
	<lastBuildDate>Sat, 23 Jul 2011 00:03:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Linux : Automatically send logs daily</title>
		<link>http://rootadmin.co.uk/2009/12/09/linux-automatically-send-logs-daily/</link>
		<comments>http://rootadmin.co.uk/2009/12/09/linux-automatically-send-logs-daily/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 00:50:50 +0000</pubDate>
		<dc:creator>Rootadmin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[attach syslog email]]></category>
		<category><![CDATA[liam]]></category>
		<category><![CDATA[Liam Somerville]]></category>
		<category><![CDATA[messages]]></category>
		<category><![CDATA[mutt]]></category>
		<category><![CDATA[OPENVPN]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[rootadmin]]></category>
		<category><![CDATA[rootadmin.co.uk]]></category>
		<category><![CDATA[send logs daily]]></category>
		<category><![CDATA[send logs email]]></category>
		<category><![CDATA[send syslog email]]></category>
		<category><![CDATA[somerville]]></category>
		<category><![CDATA[Syslog]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[ufw]]></category>
		<category><![CDATA[uncomplicated firewall]]></category>
		<category><![CDATA[vsftp]]></category>

		<guid isPermaLink="false">http://rootadmin.co.uk/?p=251</guid>
		<description><![CDATA[Well below is my first attempt at a shell script, firstly understand I am no programmer! Before we look at it, my server is running OPENVPN and Uncomplicated Firewall(I&#8217;m running Ubuntu Server) So how does it work? Firstly we declare that we are using the bash shell using #!/bin/bash Next we&#8217;re setup some vairables, the [...]]]></description>
			<content:encoded><![CDATA[<p>Well below is my first attempt at a shell script, firstly understand I am no programmer!</p>
<p>Before we look at it, my server is running OPENVPN and Uncomplicated Firewall(I&#8217;m running Ubuntu Server)</p>
<p>So how does it work?</p>
<p>Firstly we declare that we are using the bash shell using<br />
#!/bin/bash</p>
<p>Next we&#8217;re setup some vairables, the first is simply formating the date and calling itself TODAYSDATE,<br />
next we set todays archive to be archive.TODAYSDATE and call its self TODAYS_ARCHIVE</p>
<p>Next we create a directory called archive.TODAYSDATE</p>
<p>Now to the best bit, we start processing the logs<br />
- We extract todays logs out of syslog<br />
- From the extracted logs we extract the firewall (Uncomplicated Firewal/ UFW) logs to a seperate file<br />
- Now extract todays messages log<br />
- From todays extracted logs extract all OPENVPN related logs to a seperate log file<br />
- Extract todays apache access.log and error.log<br />
- Provide us with the currently running processes<br />
- Zip it all up to the /archive/ folder<br />
- back back up a directory level and delete the folder called archive.TODAYSDATE<br />
- Now use mutt to attach the zip file to a email and send it</p>
<p>Now for the script &#8211; PLEASE FEEL FREE TO USE</p>
<p>#!/bin/bash<br />
# Script By Liam Somerville, www.rootadmin.co.uk<br />
# Use freely</p>
<p>#####################################################################<br />
#                        Set up the variables<br />
#####################################################################<br />
#Set todays date<br />
TODAYSDATE=`date +&#8221;%d-%b-%Y&#8221;`</p>
<p>#Format Archive<br />
TODAYS_ARCHIVE=archive.$TODAYSDATE</p>
<p>#####################################################################<br />
#                    Finished setting up Variables<br />
#<br />
#                   Now start processing the log files<br />
#####################################################################</p>
<p># Make a directory called archive with todays date and change to that direcory<br />
mkdir $TODAYS_ARCHIVE<br />
cd $TODAYS_ARCHIVE</p>
<p>#Write the log files<br />
#Archive todays Syslog, extract all firewall related logs to firewall, then<br />
# extract messages<br />
cat /var/log/syslog | grep &#8220;`date +&#8221;%b %e&#8221; `&#8221; &gt; syslog.$TODAYSDATE<br />
cat syslog.$TODAYSDATE | grep UFW &gt; firewall_log.$TODAYSDATE<br />
cat /var/log/messages | grep &#8220;`date +&#8221;%b %e&#8221; `&#8221; &gt; messages.$TODAYSDATE<br />
#Process the OPEN VPN Server logs<br />
cat syslog.$TODAYSDATE | grep &#8220;ovpn-server&#8221; &gt; vpn_server_log.$TODAYSDATE<br />
#<br />
#Proceess Apache Logs<br />
cat /var/log/apache2/error.log | grep &#8220;`date +&#8221;%b %d&#8221; `&#8221; &gt; apache_error_log.$TODAYSDATE<br />
cat /var/log/apache2/access.log | grep &#8220;`date +&#8221;%d/%b&#8221; `&#8221; &gt; apache_access_log.$TODAYSDATE<br />
#<br />
#Process FTP Logs<br />
cat /var/log/vsftpd.log | grep &#8220;`date +&#8221;%b %e&#8221; `&#8221; &gt; ftp_log.$TODAYSDATE<br />
#<br />
# Get a list of currently running process<br />
ps aux &gt; Processes.$TODAYSDATE</p>
<p># Zip up all the logs and delete todays log<br />
zip /archive/$TODAYS_ARCHIVE.zip *<br />
cd ..<br />
rm -r $TODAYS_ARCHIVE</p>
<p>####################################################################<br />
#                     Now email the zip file<br />
###################################################################<br />
echo | mutt -a /archive/$TODAYS_ARCHIVE.zip -s &#8220;Event logs for $TODAYSDATE&#8221; you@your.email.address.com</p>
]]></content:encoded>
			<wfw:commentRss>http://rootadmin.co.uk/2009/12/09/linux-automatically-send-logs-daily/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

