Monday, 12 September 2011

Mikrotik PHP PPP User Management System

I have uploaded a simple PHP based Mikrotik PPP User Management System.

Please visit http://wiki.mikrotik.com/wiki/Basic_php_ppp_scripts for complete instructions.

You can request for more features.

Sunday, 11 September 2011

Mikrotik Bash Script

I have created a Wiki article on Mikrotik site and thought that I should share it with you all. Please follow the link below to view the article.


Please feel free to provide your important feedback

Friday, 9 September 2011

MySQL Startup Script

This is a MySQL start up script. I created this script when I faced issues in Ubuntu 10.04 LTS MySQL start up script.
This is a very handy small script which can be used not only for MySQL but for almost all services.


#! /bin/bash

JOB=/usr/sbin/mysqld

case $1 in
  start)
    $JOB &> /dev/null &
    ps aux | grep mysqld | grep -v grep | awk '{print $2}' > /tmp/mysqld.pid
    ;;
  stop)
    kill -9 $(cat /tmp/mysqld.pid)
    rm -f /tmp/mysqld.pid
    ;;
  restart)
    stop
    start
    ;;
  *)
    echo Oops! bad options
    ;;
esac
exit 0

Wednesday, 7 September 2011

Mikrotik script to create and email backup

A small script I created after going through many scripts available at the Mikrotik wiki. This is a simple script that creates a backup file of the Mikrotik RouterOS and emails the file to any email address specified in the script.


:global file ([/system identity get name] . [:pick [/system clock get date ] 7 11] . [:pick [/system clock get date ] 0 3] . [:pick [/system clock get date ] 4 6] . ".backup")
/system backup save name=$file
/tool e-mail set server=smtp.example.com
/tool e-mail set from="backup@example.com"
/tool e-mail send to="reports@example.com" subject="Mikrotik RouterOS Firewall Backup" body="Attached is the backup file of Mikrotik RouterOS" file=$file

A very useful Disk Size Monitoring script

This is a very useful and small script that I created quiet some time back when I was creating custom monitoring plugins for one my my clients.
Still I use this script to perform Disk Size Monitoring at many places that I am monitoring.

For this script to work properly, a small linux command line utility known as "mutt" needs to be installed. It is a very handy command line e-mail client. Normally this comes by default with linux, but just in case this is not present, simply use the native package manager (yum for redhat/centos/fedora and apt-get for debian/ubuntu) to install this utility.

Now for the script. It is a bit messed up.

[root@crystalnetworks.org home]# cat disksize.sh


#!/bin/bash
#
# Author : Mudasir Mirza

#Un-comment the following line to run the script in debug mode
#set -x

# Absolute path to CSV file that will be generated by script
OUTPUT="/tmp/size.csv"

rm -f $OUTPUT
NUM_COL=`df -h | head -n1 | awk '{ print NF }'`
for (( i=1; i<=$NUM_COL; i++ ))
do
COM[$i]=`df -h | head -n1 | awk -v "awkvar=$i" '{print $awkvar}'`
done
FLD=`echo ${COM[@]} | sed 's/\ /,/g'`
echo $FLD > $OUTPUT
P=`df -h | tail -n+2 | wc -l`
for (( i=1; i<=$P; i++ ))
do
CMD=`df -h | tail -n+2 | sed "${i}!d"`
CMDA=`echo $CMD | sed 's/\ /,/g'`
echo $CMDA >> $OUTPUT
done
echo | mutt -a $OUTPUT -s "Daily Disk Size Email" monitoring@example.com
###########################################################
# End of Scirpt