Sleep Timeout on TCL (and Cisco too…)

Posted by: gdelmatto  :  Category: Cisco, TCL

Being used to other languages sometime leads to false assumptions, like having the same commands every now and then.
While doing some TCL scripting on a Cisco I just had the need for a ‘sleep’ command or equivalent.

Since no ‘sleep’ exists, the ‘after’ command will do. Just supply it with the timeout in milliseconds, like this for a 10-second timeout:

after 10000

Or, with a bit more overhead, but some may think it’s more readable:

after [expr {int(10 * 1000)}]

Extract and Unify Cisco Device-Types with SNMP and Perl

Posted by: gdelmatto  :  Category: Cisco, Networking, Perl, Programming

Here’s a short script which I use to extract Cisco device-types from SNMP.
Bad enough, most of these devices return their device type ID differently, e.g. sometimes prefixed with an uppercase ‘C’, sometimes without any prefix, then again sometimes we find a suffix.

So here’s a snippet, that makes them look neat, so I can work with simple and unified looking device IDs.
Read more…

Print File Contents in Reverse Order (“reverse cat”)

Posted by: gdelmatto  :  Category: Perl, Programming, Scripting

The ‘cat’ utility serves it’s purpose print the content of a file at once. So do ‘more’ and other tools as well. But they all do in ‘forward’ mode only.
To print a file in reverse order, at least some linux distros come with the ‘tac’ command, which will do a ‘reverse cat’.
But what to do, if ‘tac’ is missing?
Read more…

RegExp Filter: Extract complete interface blocks without ‘shutdown’ statement

Posted by: gdelmatto  :  Category: Cisco, Networking, Programming, RegExp

A project I’m currently working on involges much Regurlar Expressions trickery to parse values from Cisco’s running configuration.
Here’s how to extract a complete interface block not in ‘shutdown’ state.
Read more…

Fixing “Cannot find autoconf” error while building PHP extension from a FreeBSD port

Posted by: gdelmatto  :  Category: FreeBSD, Operating Systems, PHP

Today I had to add the PHP ‘bcmath’ extension to my FreeBSD host.
Actually, that’s a fairly easy one-liner:


[root@localhost ~]# cd /usr/ports/math/php5-bcmath && make clean install

However, I ended up with a crude error message:

Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

Bummer! So let’s see how to fix this.
Read more…

Setting up Redmine on FreeBSD

Posted by: admin  :  Category: FreeBSD, HowTo's, Programming, Utilities

“Redmine is a flexible project management web application. Written using Ruby on Rails framework, it is cross-platform and cross-database.” (redmine.org)

Here’s my short primer on setting up Redmine on FreeBSD.
Read more…

Mac OS HFS+ case-insensitivenesss screws SVN

Posted by: admin  :  Category: OS X, Programming, Utilities

So I work on OS X for a few years now, but until today that I didn’t really care about the underlying HFS+ file system.
But while working on a project using SVN, I got this unexpected error message:


gianpaolo-del-mattos-macbook-pro:trunk Gianpaolo$ svn update
svn: URL 'svn+ssh://...../webinterface/files/lib/webmin' of existing directory '...../webinterface/files/lib/Webmin' does not match expected URL 'svn+ssh://..../webinterface/files/lib/Webmin'

Read more…

Shell Scripting: How to easily convert UNIX timestamp into date format

Posted by: admin  :  Category: Perl, Programming, Scripting

When writing shell scripts (bash, sh, etc) maybe you had to work with POSIX/UNIX timestamps from time to time.
While the serialized nature of the timestamp is great to work with for scripting, it’s easier for human beings to have them printed in date format.

Before you start digging around using some fancy conversion in Perl, check out the ‘date’ command first.
Read more…

Obfuscated PHP code in WordPress Themes or PHP scripts may be a security hole!

Posted by: admin  :  Category: PHP, Programming, Security

Gosh, some things really shouldn’t be done!
One thing for example is that stupid attitude to “scramble” PHP code by nesting it a zillion times using eval(), gz_deflate(), base64_encode() and str_rot13.
You find this in some “freely” available PHP scripts and some WordPress Themes as well. Actually nobody seems to care, that this may be well worth considering as a huge security hole!
Read more…

De-Scrambler for obfuscated PHP code

Posted by: admin  :  Category: PHP, Programming, Scripting, Security

Thinking about security risks of obfuscated PHP code found in some freely available PHP scripts and WordPress themes, I wrote a quick’n’dirty De-Scrambler.
Read more…