Simple Bash Script to use OS X 10.4 as a firewall

There was an unused Apple desktop machine running OS X 10.4 sitting around, so I decided to use it as a storage for our company's firewall log. The current log is then rotated and saved in /private/var/log/archived. Here's the script:

#!/bin/bash
echo Stopping Syslog...
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist
sleep 1

echo ""
printf %s "Rotating log files:"
cd /var/log
for i in edmonton.log; do
    if [ -f "${i}" ]; then
        printf %s " ${i}"
        if [ -x /usr/bin/gzip ]; then gzext=".gz"; else gzext=""; fi
        if [ -f "${i}.6${gzext}" ]; then mv -f "${i}.6${gzext}" "${i}.7${gzext}"; fi
        if [ -f "${i}.5${gzext}" ]; then mv -f "${i}.5${gzext}" "${i}.6${gzext}"; fi
        if [ -f "${i}.4${gzext}" ]; then mv -f "${i}.4${gzext}" "${i}.5${gzext}"; fi
        if [ -f "${i}.3${gzext}" ]; then mv -f "${i}.3${gzext}" "${i}.4${gzext}"; fi
        if [ -f "${i}.2${gzext}" ]; then mv -f "${i}.2${gzext}" "${i}.3${gzext}"; fi
        if [ -f "${i}.1${gzext}" ]; then mv -f "${i}.1${gzext}" "${i}.2${gzext}"; fi
        if [ -f "${i}.0${gzext}" ]; then mv -f "${i}.0${gzext}" "${i}.1${gzext}"; fi
        if [ -f "${i}" ]; then
              touch "${i}.$$" && chmod 640 "${i}.$$" && chown root:admin "${i}.$$"
              mv -f "${i}" "${i}.0" && mv "${i}.$$" "${i}" && if [ -x /usr/bin/gzip ]; then
                gzip -9 "${i}.0"; fi
        fi
    fi
done
if [ -f /var/run/syslog.pid ]; then kill -HUP $(cat /var/run/syslog.pid | head -1); fi
echo ""

cp -f /var/log/edmonton.log.1.gz /var/log/archived/edmonton_log-`/bin/date +%Y-%m-%d`.gz

sudo rm -f /var/log/edmonton.log
sudo touch /var/log/edmonton.log
sudo chgrp -v admin /var/log/edmonton.log
sudo chmod -v go+w /var/log/edmonton.log


for i in toronto.log; do
    if [ -f "${i}" ]; then
        printf %s " ${i}"
        if [ -x /usr/bin/gzip ]; then gzext=".gz"; else gzext=""; fi
        if [ -f "${i}.6${gzext}" ]; then mv -f "${i}.6${gzext}" "${i}.7${gzext}"; fi
        if [ -f "${i}.5${gzext}" ]; then mv -f "${i}.5${gzext}" "${i}.6${gzext}"; fi
        if [ -f "${i}.4${gzext}" ]; then mv -f "${i}.4${gzext}" "${i}.5${gzext}"; fi
        if [ -f "${i}.3${gzext}" ]; then mv -f "${i}.3${gzext}" "${i}.4${gzext}"; fi
        if [ -f "${i}.2${gzext}" ]; then mv -f "${i}.2${gzext}" "${i}.3${gzext}"; fi
        if [ -f "${i}.1${gzext}" ]; then mv -f "${i}.1${gzext}" "${i}.2${gzext}"; fi
        if [ -f "${i}.0${gzext}" ]; then mv -f "${i}.0${gzext}" "${i}.1${gzext}"; fi
        if [ -f "${i}" ]; then
              touch "${i}.$$" && chmod 640 "${i}.$$" && chown root:admin "${i}.$$"
              mv -f "${i}" "${i}.0" && mv "${i}.$$" "${i}" && if [ -x /usr/bin/gzip ]; then
                gzip -9 "${i}.0"; fi
        fi
    fi
done
if [ -f /var/run/syslog.pid ]; then kill -HUP $(cat /var/run/syslog.pid | head -1); fi
echo ""

cp -f /var/log/toronto.log.1.gz /var/log/archived/toronto_log-`/bin/date +%Y-%m-%d`.gz

sudo rm -f /var/log/toronto.log
sudo touch /var/log/toronto.log
sudo chgrp -v admin /var/log/toronto.log
sudo chmod -v go+w /var/log/toronto.log

for i in montreal.log; do
    if [ -f "${i}" ]; then
        printf %s " ${i}"
        if [ -x /usr/bin/gzip ]; then gzext=".gz"; else gzext=""; fi
        if [ -f "${i}.6${gzext}" ]; then mv -f "${i}.6${gzext}" "${i}.7${gzext}"; fi
        if [ -f "${i}.5${gzext}" ]; then mv -f "${i}.5${gzext}" "${i}.6${gzext}"; fi
        if [ -f "${i}.4${gzext}" ]; then mv -f "${i}.4${gzext}" "${i}.5${gzext}"; fi
        if [ -f "${i}.3${gzext}" ]; then mv -f "${i}.3${gzext}" "${i}.4${gzext}"; fi
        if [ -f "${i}.2${gzext}" ]; then mv -f "${i}.2${gzext}" "${i}.3${gzext}"; fi
        if [ -f "${i}.1${gzext}" ]; then mv -f "${i}.1${gzext}" "${i}.2${gzext}"; fi
        if [ -f "${i}.0${gzext}" ]; then mv -f "${i}.0${gzext}" "${i}.1${gzext}"; fi
        if [ -f "${i}" ]; then
              touch "${i}.$$" && chmod 640 "${i}.$$" && chown root:admin "${i}.$$"
              mv -f "${i}" "${i}.0" && mv "${i}.$$" "${i}" && if [ -x /usr/bin/gzip ]; then
                gzip -9 "${i}.0"; fi
        fi
    fi
done
if [ -f /var/run/syslog.pid ]; then kill -HUP $(cat /var/run/syslog.pid | head -1); fi
echo ""

cp -f /var/log/montreal.log.1.gz /var/log/archived/montreal_log-`/bin/date +%Y-%m-%d`.gz

sudo rm -f /var/log/montreal.log
sudo touch /var/log/montreal.log
sudo chgrp -v admin /var/log/montreal.log
sudo chmod -v go+w /var/log/montreal.log


sudo launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plist

Then, I also added the following to /etc/syslog.conf

local4.*                        /var/log/montreal.log
local6.*                        /var/log/edmonton.log
local0.*                        /var/log/toronto.log

That's it!

Category:  Apple OS X

Latest

Tik Tok algorithm is interesting

17.Apr.2024
I don't know how Tik Tok does it and honestly I don't know how its algorithm works. It can't be alg...

How to upgrade Gitlab safely with zero downtime

30.Mar.2024
GitLab is a complex piece of software. If you are planning on upgrading your self-hosted GitLab mac...

How to reduce Proxmox VE guest machine backup size

30.Mar.2024
To reduce a guest machine before you perform a backup, first set the discard flag on the guest mach...

Proxmox and CSF - LAN vmbr2 not working

29.Mar.2024
If somehow you have Proxmox & CSF for blocking outside traffic vmbr0 (WAN), and have a vmbr2 LA...

Scam text message from +1 (604) 339-2192

24.Jun.2017
Today I got a scam text message from +1 (604) 339-2192, telling me to deposit email money transfer ...

Disable free SSL from CPanel

26.Jan.2017
Recently, CPanel has been providing domain validated SSL certificate for free. However, it is quite...

Windows 2012 Server RC Evaluation ISO direct link

2.Aug.2012
I've been wanting to download the latest version of Windows 2012 but for some reasons I keep gettin...

Scam from TextWon.com/Ziinga (claiming to be BestBuy) sent by (917) 690-6874

3.Jul.2012
This morning I received a scam spam message from (917) 690-6874. Becareful because this is not a le...

Oracle VM Server on Lenovo W520 with i7-2860QM and 32GB RAM, 1.5TB RAID

2.Jul.2012
I've been curious about Oracle VM Server and wanted to try it for my own home lab. I've had the VMW...

Ubuntu 12.04 on Lenovo W520 with Intel RAID - don't waste your time

24.Jun.2012
I think Ubuntu 12.04 is a big failure. It's unstable and buggy to the point where I think it just d...

iOS 6 - How to get turn-by-turn navigation for older iPhone (3G, 4)

13.Jun.2012
iOS 6 - How to get Siri and turn-by-turn navigation for older iPhone (3G, 4): Sell your old iPhone...

Bitrig - copycat of OpenBSD

13.Jun.2012
Another day and yet another open source project got forked. Bitrig has decided to copycat OpenBSD&n...

Mobile Vendor Trend - 2012

11.Jun.2012
What Google Trends is telling you:...

GMail - Temporary Error (500) - Numeric Code 93

17.Apr.2012
At the mercy of Google when all my data (Google Apps) is in the cloud:It has been down for the last...

Drive Genius 3 - Defrag Failed

28.Mar.2012
I'm one of the folks who bought MacUpdate Spring 2012 Bundle, which includes Drive Genius 3. I've j...