scripting

Passing Command Line Arguments to a LaTeX Document


( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.181114170740the_content( )../archive.php:35
60.181514172120apply_filters( )../post-template.php:167
70.184714181348call_user_func_array ( )../plugin.php:166
80.184714181348vim_color( )../plugin.php:0
90.184714181348preg_replace ( )../wp-vimcolor.php:143
100.184814186920preg_replace ( )../wp-vimcolor.php:143
110.184814186920vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:6
120.193914205124fread ( )../wp-vimcolor.php:105

( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.181114170740the_content( )../archive.php:35
60.181514172120apply_filters( )../post-template.php:167
70.184714181348call_user_func_array ( )../plugin.php:166
80.184714181348vim_color( )../plugin.php:0
90.184714181348preg_replace ( )../wp-vimcolor.php:143
100.194914204704preg_replace ( )../wp-vimcolor.php:143
110.194914204704vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:1
120.200214204872fread ( )../wp-vimcolor.php:105

( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.181114170740the_content( )../archive.php:35
60.181514172120apply_filters( )../post-template.php:167
70.184714181348call_user_func_array ( )../plugin.php:166
80.184714181348vim_color( )../plugin.php:0
90.184714181348preg_replace ( )../wp-vimcolor.php:143
100.200614204704preg_replace ( )../wp-vimcolor.php:143
110.200614204704vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:1
120.206014204872fread ( )../wp-vimcolor.php:105

( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.181114170740the_content( )../archive.php:35
60.181514172120apply_filters( )../post-template.php:167
70.184714181348call_user_func_array ( )../plugin.php:166
80.184714181348vim_color( )../plugin.php:0
90.184714181348preg_replace ( )../wp-vimcolor.php:143
100.206614205100preg_replace ( )../wp-vimcolor.php:143
110.206614205100vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:3
120.212114205268fread ( )../wp-vimcolor.php:105

( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.181114170740the_content( )../archive.php:35
60.181514172120apply_filters( )../post-template.php:167
70.184714181348call_user_func_array ( )../plugin.php:166
80.184714181348vim_color( )../plugin.php:0
90.184714181348preg_replace ( )../wp-vimcolor.php:143
100.212514204836preg_replace ( )../wp-vimcolor.php:143
110.212514204836vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:1
120.217714205004fread ( )../wp-vimcolor.php:105

Some time ago, someone asked me if I knew a way to pass command line arguments to LaTeX documents. My first response was that this ought to be impossible; being a compiler, LaTeX cannot in any way alter it’s input files. But command line parameters can alter the output without touching the input of course.

This has kept me thinking for a while, and at the end I came up with some kind of a solution.

Let’s take a simple LaTeX file:

and call it .

We will define the output of as a command line parameter at LaTeX invocation, as follows:

Result: containing the text “hello world”. Admitted, it’s not the easiest solution, but it does make LaTeX useful inside simple batch jobs!

For more advanced LaTeX templating, I advise using Perl and Text::Template.

Posted in Open Source Adventures, scripting   No Comments »

gettext management


( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.225614196840the_content( )../archive.php:35
60.226014201028apply_filters( )../post-template.php:167
70.231714212668call_user_func_array ( )../plugin.php:166
80.231714212668vim_color( )../plugin.php:0
90.231714212668preg_replace ( )../wp-vimcolor.php:143
100.231814233080preg_replace ( )../wp-vimcolor.php:143
110.231814235236vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:57
120.237914237940fread ( )../wp-vimcolor.php:105

( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.225614196840the_content( )../archive.php:35
60.226014201028apply_filters( )../post-template.php:167
70.231714212668call_user_func_array ( )../plugin.php:166
80.231714212668vim_color( )../plugin.php:0
90.231714212668preg_replace ( )../wp-vimcolor.php:143
100.238314228052preg_replace ( )../wp-vimcolor.php:143
110.238314228376vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:13
120.243714228988fread ( )../wp-vimcolor.php:105

Anybody remember gettext? A couple of years ago I investigated the localisation system for a project and actually came to like it pretty much. Managing your .po and .mo files can be a hassle though. That’s why I created these two scripts to help me handle them:

and

These scripts will not setup the working environment nor generate full headers for new .po files. You will have to do this manually. A corresponding working environment for the scripts in their posted configuration looks like this:

.
|-- images
|   `-- favicon.ico
|-- includes
|   `-- accept-to-gettext.inc
|-- index.php
|-- locale
|   |-- en_GB.UTF-8
|   |   `-- LC_MESSAGES
|   |       |-- index.mo
|   |       |-- index.po
|   |       |-- index.pot
|   |       |-- index.po~
|   |       `-- pobackup
|   |           `-- index.po
|   |-- fr_BE.UTF-8
|   |   `-- LC_MESSAGES
|   |       |-- index.mo
|   |       |-- index.po
|   |       |-- index.pot
|   |       |-- index.po~
|   |       `-- pobackup
|   |           `-- index.po
|   `-- nl_BE.UTF-8
|       `-- LC_MESSAGES
|           |-- index.mo
|           |-- index.po
|           |-- index.pot
|           |-- index.po~
|           `-- pobackup
|               `-- index.po
|-- makemo
|-- makepo
`-- styles
    `-- index.css

Mind the accept-to-gettext.inc file, a great script written by Wouter Verhelst to convert information in HTTP ‘Accept-*’ headers to gettext language identifiers.

Posted in Open Source Adventures, scripting   No Comments »

pyfconfig — how to get ifconfig data without regular expressions


( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.251914199588the_content( )../archive.php:35
60.252214203004apply_filters( )../post-template.php:167
70.258014212140call_user_func_array ( )../plugin.php:166
80.258014212140vim_color( )../plugin.php:0
90.258014212140preg_replace ( )../wp-vimcolor.php:143
100.258214230276preg_replace ( )../wp-vimcolor.php:143
110.258214232200vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:53
120.264614234716fread ( )../wp-vimcolor.php:105

( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.251914199588the_content( )../archive.php:35
60.252214203004apply_filters( )../post-template.php:167
70.258014212140call_user_func_array ( )../plugin.php:166
80.258014212140vim_color( )../plugin.php:0
90.258014212140preg_replace ( )../wp-vimcolor.php:143
100.265014225588preg_replace ( )../wp-vimcolor.php:143
110.265014225588vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:1
120.270314226028fread ( )../wp-vimcolor.php:105

After reading this post about ifconfig output parsing by Kris, I remembered I once needed a cross-platform way to get the IP address of an interface in Python.

Of course I could just parse the output of `ifconfig`, but I really don’t like such ugly hacks. I guess I’ve got too many (bad) experiences with libwww-perl scripts I wrote for web harvesting various stuff. Basically, this is output parsing too, as HTML is generally the result of some server side script. Each time the webpage changed the way it looked (non-CSS changes) or worked, my scripts started to fail.

That’s when I decided I’ll always try to avoid such clumsy dependencies on third party software.

So, back to the Python question. I set out for a short adventure on comp.lang.python and came up with a solution after some fiddling: pyfconfig, a cross platform Python module to query for the IP address of an interface. Tested on FreeBSD x86, GNU/Linux x86 and GNU/Linux x86_64, with Python 2.4 and Python 2.5. Works just fine.

Compile with (for Python 2.5) and after an import pyfconfig, pyfconfig.ipaddr(’lo’) should return ‘127.0.0.1′ (YMMV).

No dependency on the output formatting of ifconfig. Less bugs.

Posted in Open Source Adventures, scripting   No Comments »

Poor man’s NTP


( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.278414200940the_content( )../archive.php:35
60.278814201384apply_filters( )../post-template.php:167
70.280714202496call_user_func_array ( )../plugin.php:166
80.280714202496vim_color( )../plugin.php:0
90.280714202496preg_replace ( )../wp-vimcolor.php:143
100.280714205524preg_replace ( )../wp-vimcolor.php:143
110.280714205524vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:6
120.289514206384fread ( )../wp-vimcolor.php:105

Yesterday I had to quickly (more or less) synchronize the clocks of a handful of computers I was working on. I didn’t have the time to work out an NTP based solution, so I came up with the following simple trick:

Needless to say… it worked. :-)

Posted in Open Source Adventures, scripting   No Comments »

[office] scantopdf revisited


( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.298014202256the_content( )../archive.php:35
60.298314204348apply_filters( )../post-template.php:167
70.303114210896call_user_func_array ( )../plugin.php:166
80.303114210896vim_color( )../plugin.php:0
90.303114210896preg_replace ( )../wp-vimcolor.php:143
100.303214223148preg_replace ( )../wp-vimcolor.php:143
110.303214224588vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:44
120.311014227004fread ( )../wp-vimcolor.php:105

At the airport. Bored. Started hacking up my scantopdf script to cater for multiple page documents and a simple scanner.

It depends on some external tools though and I don’t really like the way their paths are hard-coded now, but it’s useful as is, still (and very easy to change). Make sure you have pdftk, scanimage, netpnm and ghostscript installed or it won’t work for you.

Curious if it will work when I return to the office. :-)

Posted in scripting   No Comments »

[sysadmin] vhostlist


( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.318414203352the_content( )../archive.php:35
60.318714204860apply_filters( )../post-template.php:167
70.322114208912call_user_func_array ( )../plugin.php:166
80.322114208912vim_color( )../plugin.php:0
90.322114208912preg_replace ( )../wp-vimcolor.php:143
100.322214218520preg_replace ( )../wp-vimcolor.php:143
110.322214219496vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:11
120.330714221068fread ( )../wp-vimcolor.php:105

On our public web server, we are hosting a lot of stuff. Currently, we have over one hundred virtual hosts defined in Apache.

One day, I realised that I didn’t have an overview any more of all these deployments. That’s when I decided to write a simple script to produce me a list of all virtual hosts (and aliases) in HTML. As it’s all about file parsing, and I got a bit bored of Perl, I decided to write it in AWK and wrap it in sh so it can be installed as a CGI script on the same web server.

It’s still really basic, but it serves it’s purpose. Wished feature is to show a difference between ServerName’s and ServerAlias’es. This is left as an exercise to the reader.

Posted in scripting   No Comments »

[sysadmin] cupsquota.sh


( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.338814204184the_content( )../archive.php:35
60.339114206872apply_filters( )../post-template.php:167
70.345714214224call_user_func_array ( )../plugin.php:166
80.345714214224vim_color( )../plugin.php:0
90.345714214224preg_replace ( )../wp-vimcolor.php:143
100.345814230648preg_replace ( )../wp-vimcolor.php:143
110.345814232948vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:76
120.352514236124fread ( )../wp-vimcolor.php:105

Sometimes I want to know how many pages some user printed on some printer on the network from some host on the network. This script tells me just that.

It’s an awk program with a bourne shell wrapper to calculate the total amount of pages a user has printed on a host using cups.

Posted in scripting   No Comments »

[office] scantopdf


( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.359914205212the_content( )../archive.php:35
60.360214206140apply_filters( )../post-template.php:167
70.362314208040call_user_func_array ( )../plugin.php:166
80.362314208040vim_color( )../plugin.php:0
90.362314208040preg_replace ( )../wp-vimcolor.php:143
100.362414214564preg_replace ( )../wp-vimcolor.php:143
110.362414215312vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:22
120.369114217068fread ( )../wp-vimcolor.php:105

Another addition to my [office] collection of scripts. And again one which deals with a scanner. scantopdf scans an A4 paper from any SANE device and stores it as a PDf with a given filename.

Posted in scripting   1 Comment »

[office] copymachine


( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.376614205860the_content( )../archive.php:35
60.376914206932apply_filters( )../post-template.php:167
70.379414209556call_user_func_array ( )../plugin.php:166
80.379414209556vim_color( )../plugin.php:0
90.379414209556preg_replace ( )../wp-vimcolor.php:143
100.379514216468preg_replace ( )../wp-vimcolor.php:143
110.379514217188vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:24
120.387014218836fread ( )../wp-vimcolor.php:105

At the office, we have a scanner attached to a desktop (elisa), published as a :net device by SANE. Additionally, a network printer (gutenberg) is attached to the network. This script allows anyone on the network to combine both as a (basic) copymachine.

Remember it’s statically configured for A4 papersize (215mm x 297mm).

Posted in scripting   No Comments »

[office] dvitopdf.sh


( ! ) Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/bbbart/www/htdocs/blog/wp-content/plugins/vimcolor/wp-vimcolor.php on line 105
Call Stack
#TimeMemoryFunctionLocation
10.000154108{main}( )../index.php:0
20.000257812require( '/home/bbbart/www/htdocs/blog/wp-blog-header.php' )../index.php:17
30.155613997152require_once( '/home/bbbart/www/htdocs/blog/wp-includes/template-loader.php' )../wp-blog-header.php:16
40.156814062416include( '/home/bbbart/www/htdocs/blog/wp-content/themes/svelt/archive.php' )../template-loader.php:52
50.394314206580the_content( )../archive.php:35
60.394714207456apply_filters( )../post-template.php:167
70.397114209912call_user_func_array ( )../plugin.php:166
80.397114209912vim_color( )../plugin.php:0
90.397114209912preg_replace ( )../wp-vimcolor.php:143
100.397114214952preg_replace ( )../wp-vimcolor.php:143
110.397114215284vimcolor_process_color( )../wp-vimcolor.php(143) : regexp code:5
120.404414216448fread ( )../wp-vimcolor.php:105

At our office we tend to document almost everything with LaTeX. This script is one which has saved us a lot of time already with creating high quality PDF documents.

Basically, it’s just an alias to simplify creating prepress quality A4 PDFs of a DVI file, typically created with LaTeX and hyperref with the dvipdfm driver.

It’s the “prepress” setting at the end which guarantees the quality of the output.

Posted in scripting   No Comments »