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

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
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:


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

tail -100 /var/log/apf_log | mail -s "APF Firewall Status"

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:


For yes.

6. It will then say:

"File Name to Write:":

Hit enter to save

You have now created and saved your new file ( 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


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:


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

Check your mail!


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

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

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 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) 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:


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"

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

ls -l /var/log | mail -s "Email Subject"

To make a pipe symbol press shift backslash.


Sponsored Links

Related posts from
Title Type Date Posted
gigas Listing 2015-02-16 20:05:34
GlowHost Listing 2015-01-30 21:01:30
UK Web Host Daily Internet Completes NameHog Acquisition Web Hosting News 2014-08-08 11:21:05
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

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
Log in with your username and password

Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Web Hosting News:
WHT Membership
WHT Membership



Welcome to

Create your username to jump into the discussion! 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?