hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Web Hosting Talk Tutorials : Hosting Security and Technology Tutorials : APF firewall. Daily automated email showing firewall status
Reply

Forum Jump

APF firewall. Daily automated email showing firewall status

Reply Post New Thread In Hosting Security and Technology Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 06-24-2004, 04:18 PM
Charles Sweeney Charles Sweeney is offline
New Member
 
Join Date: Jun 2004
Location: Scotland, UK.
Posts: 0

APF firewall. Daily automated email showing firewall status


This is how to get your server to send you a daily email showing the status of your APF firewall. In other words, letting you know if it's running or not!

This is done by setting up a cron job.

A cron job is simply an automated task carried out by the server at regular specified intervals, usually hourly, daily, weekly etc.

We are going to get the server to check your APF firewall log on a daily basis, and output the result to an email address of your choosing. To do this, we are going to create a new file containing the instructions in the relevant cron directory.

Lets do it:

This assumes you are using SSH and are logged on as root.

1. Change to the cron.daily directory. Type:

cd /etc/cron.daily

2. Create a new file. Type:

pico apfstatus.sh

3. You are now in the pico text editor. Type:

#!/bin/bash
tail -100 /var/log/apf_log | mail -s "APF Firewall Status" you@yourdomain.com


In this case, this should be two lines only. Pico adds a carriage return to the end of the last line, so you do not need to do this.

4. Exit as follows:

Press "Ctrl" and "x"

5. You will be prompted to save the file thus:

"Save modified buffer..." Type:

y

For yes.

6. It will then say:

"File Name to Write: apfstatus.sh":

Hit enter to save

You have now created and saved your new file (apfstatus.sh) in the /etc/cron.daily directory.

7. Next you will need to change the permissions of your file so that it can run. Type:

chmod 755 apfstatus.sh

Finished!!

You will now get a daily email showing the status of your firewall.

Lets test it (this assumes you are still in the /etc/cron.daily directory). Type:

./apfstatus.sh

You will not see anything happening on the screen as the output is being sent to email.

Check your mail!

Notes:

1. If you want to make it run hourly, put (or create) the file (apfstatus.sh) in the /etc/cron.hourly directory. This will send you an email every hour.

2. You don't have to name the file "apfstatus.sh", you can call it anything_you_like.sh

3. "tail -100" asks the server to output the last 100 lines of the APF log file (apf_log). You can change this to any number. If you make it much bigger, you will get a large email!

The most important line in the log is the last one, this shows the current status of your firewall, so you don't really need hundreds of lines unless you just like to see it's doing its stuff!

If your firewall is up and running, the last line should read (not literally):

(date) (server name) apf(number): firewall initalized

4. "APF Firewall Status" is the subject of the email that is sent. You can change this to anything you like, between the quotes.

5. Replace you@yourdomain.com with your own email address!!

When I first tried this on a new server, my mail provider rejected the email because the server name (hostname) myserver.mydomain.com was "unroutable". This was because my server name was not in the DNS. You must add it to whatever DNS you are using, pointing it to the IP address of your server, so that you can be sure of getting the mails from your server.

6. You can experiment with different cron jobs, making a new file for each job for simplicity's sake.

The important thing is to include the "shebang" line first:

#!/bin/bash

What follows this is just regular Linux commands. Put each command on a new line.

So you can get the file to do practically anything you can do at the command prompt, then email it to you if desired.

Think of it as the file entering the Linux commands for you!

This is the command that outputs to email:

mail -s "APF Firewall Status" you@yourdomain.com

Make sure that you have " | " (space pipe space) after your Linux command like:

ls -l /var/log | mail -s "Email Subject" you@yourdomain.com

To make a pipe symbol press shift backslash.

Enjoy.



Sponsored Links
Reply

Related posts from TheWhir.com
Title Type Date Posted
Google has Access to Incoming and Outgoing Gmail Messages According to Updated Terms of Service Web Hosting News 2014-04-15 12:24:10
GoGrid Adds New Firewall Services to Cloud SDN Architecture Web Hosting News 2013-04-11 10:50:21
UK Web Host Daily Internet Launches Dedicated Servers Packages Web Hosting News 2013-01-29 14:36:15
Interoute Launches Cloud Firewall Service for Real-time View into Security Threats Web Hosting News 2012-12-04 16:00:56
Web Host HostGee Rolls Out Managed Firewall Cluster Service Web Hosting News 2012-10-22 15:36:38


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?