Bash Script – Pcapsipdump Spool Directory File Rotation – OR – Rotate Directories Based on YYYYMMDD Format

In the config file for the pcapsipdump program, there is a retention option where you are supposed to be able to enter the number of days to keep the directories in your spool folder and it should auto purge out the old directories/files, however, this option either doesn’t appear to be implemented yet or doesn’t work if you run the app as a different user (could be a permissions issue maybe?).

Anyhow, this script is my solution to the problem. It could also very easily be modified and used where someone needs to search and delete directories that are based on YYYYMMDD format with the ability to whitelist or ignore certain directories, hence the alternate title. Yet another alternate title could even be “Bash Script Functions – Convert YYYYMMDD to Unix Time and Vice Versa” but obviously the script would need modified a little because it has been tailored to fit my needs.

When run as a cron job, the script will grab both the spool directory and the retention period from the pcapsipdump config file and will purge out any old folders based on YYYYMMDD format so they aren’t eating up all your valuable disk space.

I also added a couple of noteworthy user-configurable options. The first being a directory whitelist feature (IGNORE_DIRS array), this option can be used in situations where there are directories that you don’t want purged or would like to keep the data indefinitely and that can also be used in conjunction with the PURGE_ALL feature to delete out any subdirectories that aren’t specifically listed in the whitelist if you are a clean freak.

Download it now – pcaprotate.sh

#!/bin/bash
#
# pcapsipdump file rotation
# By Nathan Thomas
# 12/05/2014
#

### VARS ###
# Location of the pcapsipdump config file
CONF_FILE='/etc/default/pcapsipdump';

# Keep the spool folder clean - Delete all folders (except those in the ignored directories array)
# yes - Keep the spool folder free from any directories not in the ignore list
# no - Don't worry about any other random folders in the spool directory
 Continue reading "Bash Script – Pcapsipdump Spool Directory File Rotation – OR – Rotate Directories Based on YYYYMMDD Format"

Asterisk – Modular Dialplan

This is just a table of contents of the various Asterisk dialplan modules I have created over the last couple of years and am releasing to the general public as open-source in hopes that somebody finds them as useful as I do.

In my days as a Network Administrator managing six interconnected, fully-meshed branch office PBX’s at a telemarketing firm, maintaining six separate dialplans became a tiresome effort which ultimately led to my creation of the dialplan modules.
Continue reading “Asterisk – Modular Dialplan”

Mikrotik Scripting – Array Push Function

Since the scripting language at the moment on Router OS version 6.13 is lacking in the array editing department, here is a simple array push function I created.

# Usage: [$arrayPush <$array name> <value> <key position to place value (0-n or -1)>]
# Input an array name, value, and the key position to push the value to. To push value to the end of the array, enter -1.
# If array doesn't already exist, you must declare the variable and set it to "" before calling the function.
 Continue reading "Mikrotik Scripting – Array Push Function"

Mikrotik Scripting – Function to Split an IP Address into an Array

If you are unfamiliar with Mikrotik networking equipment, do yourself a favor and check them out at mikrotik.com or routerboard.com. Mikrotik uses Router OS, a Linux based operating system. In my eyes, they are every bit as comparable to Cisco at a fraction of the price with an impressive and robust GUI. I’ve been using them in production environments for six years with outstanding results. What other networking equipment has it’s own scripting language? None that I know of. The CCR series of routers with up to 36 processor cores are unparalleled in performance and flexibility.
Continue reading “Mikrotik Scripting – Function to Split an IP Address into an Array”

Bash Script – Move Asterisk Call Files into Spool Directory

After running into permission issues trying to get PHP’s shell_exec command to chown call files as the asterisk user(which only root can do), I decided to make this script.

As a side note, you should be able to get the shell_exec command to work using sudo by adding the www-data user to the sudoer’s file without a password but that wouldn’t work in my particular environment. The server I was working on was extremely outdated and didn’t even have sudo installed.

Add this to /etc/sudoers
www-data ALL=NOPASSWD: /path/to/script

The following code runs the script as a daemon. You will need to update rc to start this script at default run levels and also make sure to chmod +x this file to make it executable.

filename: /etc/init.d/mvcallfile

#!/bin/bash
# Move asterisk call file daemon startup script
# Author: Nathan Thomas

PROG=mvcallfile
 Continue reading "Bash Script – Move Asterisk Call Files into Spool Directory"

Startup Script for OpenMeetings Open-Source Video Conferencing Server

/etc/init.d/openmeetings startup script for Ubuntu Server 12.04.2
OpenMeetings Version 2.0-INCUBATING

A few notes:
– Make sure to change path for RED5_HOME variable
– Make sure to chmod +x the init script
– This assumes openmeetings is running under a user/group with the same name
– This assumes you are using libreoffice (not openoffice) for the whiteboard file import service

#!/bin/bash
#
# Author: Nathan Thomas
#
### BEGIN INIT INFO
# Provides:          red5
# Required-Start:    $local_fs $remote_fs $network $syslog $named $time
# Required-Stop:     $local_fs $remote_fs $network $syslog $named $time
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Start/stop OpenMeetings java based conferencing webapp
### END INIT INFO
PROG=red5
DESC="Red5 flash streaming server"
RED5_HOME=/usr/local/openmeetings
DAEMON=$RED5_HOME/$PROG.sh
PIDFILE=/var/run/$PROG.pid
# Plugin Variables
#OO_HOME=/usr/lib/openoffice/program
OO_HOME=/usr/lib/libreoffice/program
 Continue reading "Startup Script for OpenMeetings Open-Source Video Conferencing Server"