Archive for the ‘Tech Tips’ Category

Tech Tip: Multi-line Perl regex pattern match

Yesterday, I encountered an analysis issue that appeared to be resolvable with a simple pattern replacement technique. 
(more…)

Popularity: 34% [?]

Quick file & directory cleanup tools

Every sys admin needs to quickly free up disk space from time to time, and here are two well-tested scripts I use for exactly this purpose.

The first is a simple command-line use of exec that uses find to construct of list of matching file names, in this case all gzipped tarballs, and then runs the rm command on them.  The curly braces "{}" act as a holder for each file name from the list, and the trailing "\" is used to escape the ";", so that it is passed to find as a literal command terminator.

#find . -name *.tar.gz -exec rm {} \;

You may find (pun intended) that you need a slightly more sophisticated way to construct the list of things to remove.  For example,  to recursively delete all files & directories from an arbitrary depth in the file-system, except for special files or directories.  To accomplish this, I use a small Perl utility I wrote that uses the File::Find module. 

Here is the actual script I use generalized out with a fake $top and /some-pattern-to-exclude/. This script will crawl down (actually the direction that finddepth goes is up) a list of files & directories, and unless the pattern is matched, each file in the directory & then the directory itself is deleted.

How does this work?  Pretty simple – the File::Find module loads some routines, one of which is finddepth. The first argument it expects is a routine to run against all files & directories found, starting at the location named in the second argument.  The wanted routine is run on each element in finddepth’s list & you can use  finddepth’s variables to make your wanted routine smarter.

Tags: , ,

Popularity: 4% [?]

Converting .DOC to .PDF. Is this difficult?

If you are using a Mac running a recent version of OSX, the answer is No.  In fact this is super easy and is available from inside Microsoft Word.   If you run Windows, this feature isn’t available without an additional plugin from a third-party.

 

(more…)

Popularity: 1% [?]

Gmail, Apple Mail & the iPhone

Since Gmail began supporting IMAP, setting up Gmail to work with both Apple Mail & the iPhone is a common need for those of us with both iPhones and new Macbooks.

I began using Gmail about two weeks and had noticed the inconsistencies mentioned in the below article, and was both pleased to see that the solution was so simple as well as slightly embarrassed that I hadn’t yet resolved the issue myself.

Here’s the HOWTO:

http://5thirtyone.com/archives/862 

Tags: , , ,

Popularity: 1% [?]

AJAX Logfile Tailer & Viewer

Recently I had a need for a simple logfile viewer for use in some stuff we have planned at Freepository. But this log file viewer had a few requirements that made it unique: it had to get the log file contents from the server in small chunks, not tie up the browser (such as an old-style synchronous request would do), and refresh in the browser without reloading the page.

I thought I could easily find one that someone had already written, but Google was not my friend. I found nothing even close, so I wrote my own. Here it is.

Working example:  https://freepository.com/ajax-logtail-viewer/ajax-logtail-viewer.php

(more…)

Popularity: 96% [?]

Tech Tip: Publishing iCal Calendar in Multiple Places

Recently I had a need to publish a calendar in more than one location. Simple, right? Just use Google calendar, Boxes, or one of the other free services. Not quite. I don’t want to manage any users, nor give anyone direct access to an account that is hosting the calendar. I want to publish, not provide direct access to, the calendar.

(more…)

Popularity: 19% [?]

A Powerful Custom Spamassassin Rule

Tech Tip – Spamassassin Custom Rule

I had been inundated with so much spam lately that I added some custom rules to my spamassassin setup. These rules are added to your local.cf (don’t put them in /usr/share/spamassassion, as they’ll get overwritten with the next SA update). The single most useful one for me in this bunch is the LOCAL_RETURNED_MAIL rule.

(more…)

Popularity: 31% [?]

Tech Tip of the Day: Quick file deletion

Here’s another quick tip.  If you have a large directory tree (hundreds or thousands of nested levels), and you need to find and delete a set of files from the tree, consider this one-line approach:

cd [target-dir-top-level];for i in `find . -name \*tar.gz`; do rm -f $i; done

Replace my pattern ‘tar.gz’ with one that matches the files you wish to delete.

Tags: , ,

Popularity: 12% [?]

Tech Tip of the Day: MySQL binary export

This is a short and sweet tech tip. If you have binary data, such as images or zip files, stored in a mysql database, this technique will export those blobs (binary large objects) back to the file system.

Case:

Bugzilla attachments exist in mysql that now must be exported to another bug tracking system.

Approach:
Run this query

select thedata from attachments where bug_id='224' and mimetype not like 'text/plain' and mimetype not like 'text/hmtl' into dumpfile '/data/bug-224-attachment.zip';

for each bug that contains a binary attachment. You can extend this approach by writing a script that queries for all bugs with attachments, then acts only on those those that are binary attachments. Since you may wish to include the file type attachment in the dumpfile name, consider adding an additional loop that checks for the mimetypes that correspond to each of the various binary formats (jpg, zip, etc.). Pass both the bug_id and the mimetype into the filename that you create in the dumpfile.

Tags: , ,

Popularity: 6% [?]

Tech Tip of the Day: mod_rewrite & AllowOverride

Recently, an upgrade of the OS on the commavee server resulted in the blog post URLs failure to resolve. Earlier blog posts, with the date-and-post title formatted URL, were now unresolvable. This meant that every post in the search engines (and even the site itself) resulted in a 404 Not found error. It took a bit of investigation, but the solution was straight-forward.

(more…)

Popularity: 29% [?]