Scripts Section.

EGLUG hope that you contribute your information back into this wiki page (via the Edit tab at the top of the page if you are register user).

Alaa's tc shaping scripts

I'm putting these here mainly for DarknessWolf, one day I suppose I'll explain them (or someone who knows more will).

the scripts are very much shorewall oriented

/etc/shorewall/params

##############################################################################
NET_IF=eth0

#maximum bw for the interface
MAX_BW=90mbit

#shaped upstream BW
TC_BW=200kbit

#shaped downstream BW
TC_DOWN_BW=400kbit

#special BW for LAN traffic, I no longer use that
#TC_BW_15=112kbit

#bw classes
TC_BW_20=112kbit
TC_BW_25=56kbit
TC_BW_30=16kbit
TC_BW_35=16kbit


#LAST LINE - ADD YOUR ENTRIES ABOVE THIS ONE - DO NOT REMOVE

''/etc/shorewall/tcrules

#MARK           SOURCE          DEST            PROTO   PORT(S) CLIENT PORT(S)

#default low port
30		$FW		0.0.0.0/0	tcp	0:1024,ircd
30		$FW		0.0.0.0/0	tcp	-	0:1024,ircd

#high priority
20		$FW		0.0.0.0/0	udp
20		$FW		0.0.0.0/0	icmp
20		$FW		0.0.0.0/0	tcp	ssh
20		$FW		0.0.0.0/0	tcp	-	ssh
25		$FW		0.0.0.0/0	tcp	http,https	-
25		$FW		0.0.0.0/0	tcp	-	http,https


#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE

/etc/shorewall/tcstart

# flush rules on this interface
#run_tc qdisc del dev $NET_IF root
#echo "		flush rules on $NET_IF"

# add a main parent handle

run_tc qdisc add dev $NET_IF root handle 10: htb default 35

run_tc class add dev $NET_IF parent 10: classid 10:1 htb rate $TC_BW ceil $TC_BW quantum 200

run_tc class add dev $NET_IF parent 10:1 classid 10:20 htb rate $TC_BW_20 ceil $TC_BW prio 2 quantum 200
run_tc qdisc add dev $NET_IF parent 10:20 sfq perturb 10

run_tc class add dev $NET_IF parent 10:1 classid 10:25 htb rate $TC_BW_25 ceil $TC_BW prio 4 quantum 200
run_tc qdisc add dev $NET_IF parent 10:25 sfq perturb 10

run_tc class add dev $NET_IF parent 10:1 classid 10:30 htb rate $TC_BW_30 ceil $TC_BW prio 6 quantum 200
run_tc qdisc add dev $NET_IF parent 10:30 sfq perturb 10

run_tc class add dev $NET_IF parent 10:1 classid 10:35 htb rate $TC_BW_35 ceil $TC_BW prio 7 quantum 200
run_tc qdisc add dev $NET_IF parent 10:35 sfq perturb 10

run_tc filter add dev $NET_IF parent 10:0 protocol ip handle 15 fw flowid 10:15
run_tc filter add dev $NET_IF parent 10:0 protocol ip handle 20 fw flowid 10:20
run_tc filter add dev $NET_IF parent 10:0 protocol ip handle 25 fw flowid 10:25
run_tc filter add dev $NET_IF parent 10:0 protocol ip handle 30 fw flowid 10:30
run_tc filter add dev $NET_IF parent 10:0 protocol ip handle 35 fw flowid 10:35

#tc qdisc add dev $NET_IF handle ffff: ingress
	
tc filter add dev $NET_IF parent ffff: protocol ip prio 49 u32 match ip src \
   192.168.0.0/16 police rate $MAX_BW burst 100k drop flowid :1

tc filter add dev $NET_IF parent ffff: protocol ip prio 50 u32 match ip src \
   0.0.0.0/0 police rate $TC_DOWN_BW burst 10k drop flowid :2

EGLUG backup script

#!/bin/bash
#mysqlbackup is script writen to dump eglug databases
#+ Diaa Radwan

DATE=$(date +%d-%m-%y)
BACKUP_PATH='path/to/backups'
DBACKUP_PATH='/path/to/ocument_root'
DB_NAME='dbname'
DB_USER='dbuser'
PASSWORD='pass'
DOCUMENTROOT='/path/to/docroot'
MYDUMP_OPTIONS='--add-drop-table -acv  --compatible=mysql40 --host dbhost'

      case "$1" in

        databases)
        for db in $DB_NAME ;do
        mkdir -p $BACKUP_PATH/$DB_NAME/$DATE
        mysqldump $MYDUMP_OPTIONS -u$DB_USER -p${PASSWORD} $db > $BACKUP_PATH/$DB_NAME/$DATE/${DB_NAME}.mysql
        tar cjvf $BACKUP_PATH/$DB_NAME/$DATE/${DB_NAME}.mysql.tar.bz2 $BACKUP_PATH/$DB_NAME/$DATE/${DB_NAME}.mysql
        rm -f $BACKUP_PATH/$DB_NAME/$DATE/${DB_NAME}.mysql

        done

           ;;
          tables)
          for db in $DB_NAME
          do
                mkdir -p $BACKUP_PATH/$DB_NAME/$DATE/dbtables
          for tables in `echo "show tables" | mysql -u$DB_USER -p${PASSWORD} $DB_NAME | grep -v "Tables_in_"`
          do
        mysqldump $MYDUPM_OPTIONS -u$DB_USER -p${PASSWORD} $DB_NAME $tables > $BACKUP_PATH/$DB_NAME/$DATE/dbtables/$tables.mysql
          tar cjvf $BACKUP_PATH/$DB_NAME/$DATE/dbtables/$tables.mysql.tar.bz2 $BACKUP_PATH/$DB_NAME/$DATE/dbtables/$tables.mysql
          rm -f $BACKUP_PATH/$DB_NAME/$DATE/dbtables/$tables.mysql
          done
          done
           ;;
        docroot)
        mkdir -p $DBACKUP_PATH
        tar cjvf $DBACKUP_PATH/eglug.org_docroot_${DATE}.tar.bz2 $DOCUMENTROOT
        ;;

        dt)
           sh $PWD/$0 databases
           sh $PWD/$0 tables
           ;;
                *)
             echo "USAGE: $0 {tables|databases|dt|docroot}"
        esac

code hacks

contributed code goes here

nseries

/* nseries
complement the series program,
this program reads a list of strings and adds
an inceremneting postfix each time a string is read
for instance it´ll take an input of foo foO fOO FOO
and output foo1.gif foO2.gif fOO3.gif FOO4.gif

may be used to creat complex download lists

Alaa The Great
3/1/2002
*/

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstdio>
using namespace std;

/* program takes 4 arguments 1-start of series,
2-number of digits (used to pad leading zeros)
and 3-a postfix string value to add after each increment
*/

int main(int argc, char *argv[]) {

int count,pad;
char *postfix; //prefix[256];
char a;
string prefix;
prefix="";
if (argc<4) {
cout<<"need three arguments please"<<endl;
return 1;
}

count=atoi(argv[1]);
pad=atoi(argv[2]);
postfix=argv[3];

do {
a=getchar();
if (a=='\n'||a==EOF&&prefix!="") {
cout<<prefix;
if (count!=0) for(int k=pad; pow(10.0,(k-1))>count; k--) cout<<0;
else for (int k=pad; k>1; k--) cout<<0;
cout<<count<<postfix<<endl;
count++;
prefix="";
}
if (a!='\n'&&a!=EOF) prefix=prefix+a;
} while (a!=EOF);

return 0;
}

series

/* Series Generator
generates a string with a numeric series in the middle,
like foo01.gif foo02.gif .... foo99.gif
programs output may be redirected as its input
allowing the creation of very complex series
like /year1981/foo01.gif .... /year2002/foo90.gif
useful in creating download lists
Alaa The Great
3/1/2002
*/

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstdio>
using namespace std;

void generate(int start, int end, int pad, char *postfix, string prefix ) ;

/* program should have at least 4 arguments
  1-first and 2-last values of the series
  3-number of digits (needed to pad leading zeros)
  4-string after the series
  any arguments that follows will be assumed to be
  a string to generate a series for (string at the begining of the series)
  if only 4 arguments are given the program asks for input of string
  to put in the begining of the series (terminates when EOF is enetered) */
 
int main( int argc, char *argv[]) {
int start, end, pad;
char *postfix;
char a;
string prefix;
prefix="";
if (argc<5) {
cout<<endl<<"need more arguments"<<endl;
return 1;
}

start=atoi(argv[1]);
end=atoi(argv[2]);
pad=atoi(argv[3]);
postfix=argv[4];
if (argc==5) {
do {
a=cin.get();
if (a=='\n'||a==EOF&&prefix!="") {
generate(start,end,pad,postfix,prefix);
prefix="";
}
if (a!='\n'&&a!=EOF) prefix=prefix+a;
} while (a!=EOF);
}
else {
for (int i=5; i<argc; i++)
generate(start, end, pad, postfix, argv[i]);
}
return 0;
}

void generate(int start, int end, int pad, char *postfix, string prefix) { 
for (int count=start; count<=end; count++) {
cout<<prefix;
if (count!=0) for(int k=pad; pow(10.0,(k-1))>count; k--) cout<<0;
else for (int k=pad; k>1; k--) cout<<0;
cout<<count<<postfix<<endl;
}
}