In this article I'm going to show you how to create a stat parsing script, which will allow you to get a quick historical view of your website's daily visitor statistics.

Sometimes it's nice to be able to see at a glance the overall level of traffic that your website receives. This can help you see if an average increase in your level of traffic might be the cause of recent resource usage problems you've been having.

Create bash stat parsing script

Using the steps below I'll show you how to create a bash stat parsing script that will go through the Webalizer logs stored on your account and put all of the information into a single HTML report for you.

  1. Login to your cPanel.
  2. Under the Files section, click on File Manager, then select Home Directory and click on Go.
  3. At the top-left, click on + New File, name the file genSTATS and click on Create New File.
  4. Now right-click on the genSTATS file and click on Edit.

    Now enter in the following code, making sure to edit user=userna5 with your own cPanel username:

    #!/bin/bash

    user=userna5
    logPath=/home/$user/tmp/webalizer/

    rm -rf /home/$user/STATS.htm

    for log in `find $logPath -type f -name "usage*" -exec grep "daily_usage_" {} \; | sed 's#_# #g' | awk '{print substr($4,1,6)}' | sort -n`; do awk /"Daily usage for "/,/\\/TABLE/ $logPath"usage_"$log".html" | grep -v "IMG SRC" >> /home/$user/STATS.htm; done

    Then click on Save Changes at the top-right.

Create PHP script to run stat script

Now that you've already created a bash script to compile your stats into a single HTML report, we can also create a PHP script that will allow you to run the bash script after providing a username and password, and view the compiled HTML report.

  1. Login to your cPanel.
  2. Under the Files section, click on File Manager, then select Web Root and click on Go.
  3. At the top-left, click on + New File, name the file genSTATS.php and click on Create New File.
  4. Now right-click on the genSTATS.php file and click on Edit.

    Enter in the following code, making sure to edit the /home/userna5/genSTATS section with your own username.

    <?php
    $user = $_POST['user'];
    $pass = $_POST['pass'];

    if($user == "admin"
    && $pass == "pass")
    {
    exec ("/bin/bash /home/userna5/genSTATS");
    include("../STATS.htm");

    }
    if(isset($_POST))
    {?>

    <form method="POST" action="genSTATS.php">
    User <input type="TEXT" name="user"></input>
    Pass <input type="TEXT" name="pass"></input>
    <input type="submit" name="submit"></input>
    </form>
    <?}
    ?>

  5. Now when you access the PHP script on your website http://example.com/genSTATS.php, you'll be prompted with a username and password prompt, these need to match what is set in the PHP script for $user == "admin", and $pass = "pass". After filling in these credentials, click on Submit and you should then see the full stats report.
    gen stats fill in credentials click on submit
    gen stats view report

You should now know how to create a stat parsing script on your account, so that you can get a quick glance of your daily visits very easily.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve our Support Center:
Email Address
Optional, but our team may contact you for more information.
Like this Article?

Post a Comment

Name:
Email Address:
Comment:
Are you a bot?
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!