Archive for the ‘Scripting’ Category

Atmel AVR Fuse Settings

Saturday, September 30th, 2006

I’m lazy and don’t like reading datasheets. I do, however, enjoy writing in PHP. Here is a little web app I wrote to simplify deciding what fuse bits to program on my AVRs. I wrote it in a hurry, so there might be bugs. If you fry your AVR don’t come running to me. 🙂

AVR Fuse Settings

Perl GetOpt Not Working

Thursday, July 6th, 2006

I have run into this same problem a few times so I am documenting it here. When using GetOpt::Long and friends I would be mystified when the options were ignored. For example:


use strict;
use warnings;
use Getopt::Long;
my $debug = 0;

my $result = GetOptions( "debug" => $debug );
print "Debug flag is $debug\\n";
wriley ~/bin> ./
Debug flag is 0
wriley ~/bin> ./ --debug
Debug flag is 0
wriley ~/bin>

The options are completely ignored! A short time of googling later and I remembered the solution.


use strict;
use warnings;
use Getopt::Long;
my $debug = 0;

my $result = GetOptions( "debug" => \\$debug );
print "Debug flag is $debug\\n";
wriley ~/bin> ./
Debug flag is 0
wriley ~/bin> ./ --debug
Debug flag is 1
wriley ~/bin>

The key is escaping the $ in the GetOptions() statement. If you don’t escapey, it don’t workey!

Adding a large number of devices to Cacti

Wednesday, June 28th, 2006

There is a very nice open source snmp graphing and monitoring package avaiable called cacti. I have used it for almost a year now and have been very pleased with its functionality and ease of use.

Recently at work I had the need to graph a large number (300) of network devices and a handful of Linux servers. Being the sort of guy that would rather write scripts than manually enter 300 devices via the cacti web interface, I cobbled together some perl and php code. I had a list of network devices in a CSV file.

The format of the file is:

ID,City,State,IP Address.

If you use the scripts below you will need to edit them to fit your own device data. They are provided for illustration purposes and will most likely not work for you “out of the box”.

Update See this thread for more advanced scripts.

Process to add hosts and create graphs for each

  1. Branches.CSV branches.csv
  2. Check branches.csv for empty IP address fields and remove
  3. branches.csv > branches.sql
  4. branches.sql ==> DB
  5. branches.csv > host_graph.sql
  6. host_graph.sql ==> DB
  7. branches.csv > host_snmp_query.sql
  8. host_snmp_query.sql ==> DB
  9. foreach host_id do php run_data_query.php $host_id
  10. foreach host_id do php run_host_new_graphs.php $host_id
  11. Clear Poller Cache (php rebuild_poller_cache.php)

Process to add each host to proper state in graph tree

  1. create alphabetical flat file of state abbreviations, states
  2. states > branches-states.sql
  3. branches-states.sql ==> DB
  4. branches.csv > graph_tree_items.sql

Autocreate thresholds

  • foreach host_id do php run_autocreate.php $host_id




ISPConfig Whitelist/Blacklist

Monday, May 15th, 2006

I have recently started using an open source Linux server management package called ISPConfig. It is a wonderful piece of software and has made managing my server a breeze. Out of the box it currently does not support spamassassin whitelists or blacklists for the email users. A few hours of hacking later I had a working solution. This is far from perfect, so please don’t laugh. Feel free to improve it!


These patches are against ISPConfig version 2.2.2.

Patch1 for files in /home/admispconfig on my system

Patch2 for files in /root/ispconfig on my system

Patch3 for English language file

If you are unfamiliar with using patch, see this link for some help.

Update: I forgot to include the database tables change.
ALTER TABLE `isp_isp_user` ADD `spam_wlist` TEXT AFTER `spam_hits`;
ALTER TABLE `isp_isp_user` ADD `spam_blist` TEXT AFTER `spam_wlist`;

Update: You can use the form editor to add two largetextarea fields named spam_wlist and spam_blist to the Spam and Antivirus layer of the ISP User form. This will add the proper columns in the isp_isp_user table in the database.