Blog of Leonid Mamchenkov

You just stepped in a pile of posts.

Entries Tagged as 'scripts'

Analysis of two perl lines

Posted in All on July 6th, 2005 · 9 Comments

Today I saw these two lines in one backup script that was written in perl:

my $d = (localtime())[6];
$d = $d=~/[067]/ ? 0 : $d % 2 + 1;

Does this look cryptic to you? Probably not. But I wanted to write something and thought that these two lines won’t be that obvious for everyone out there. So I decided to explain exactly what goes on.

Before I start, I have to say that these are not just any two random lines of perl code. These are very useful lines that provide a short and elegant solution to a rather common problem. Read on if you interested.

[Read more →]

→ 9 CommentsTags: , , , , , , , ,

Telling Gnu Arch the truth

Posted in All on June 15th, 2005 · 2 Comments

Yet another problem (and solution) that I’ve stumbled across while using Gnu Arch. We have two branches in our archive: program--vendor--0.1 and program--local--0.1. Vendor’s version has all the source files in SomeDirectory, while our local version has all source files in somedir. Except for the name and few local changes, these two directories are practically identical.

But when we were creating branches and importing code, we weren’t very careful and ended up with these directories and files having different arch IDs. This makes comparing two source trees close to impossible, as arch thinks that directory SomeDirectory was removed together with all its content and directory somedir was added together with a bunch of files.

Telling Arch the truth is very simple. Basically, all that needs to be done is =id and *.id files under all .arch-ids/ directories in one source tree should be copied to the appropriate places in the other source tree. After that tla commit should be done.

In order to minimize the pain of manual labour, I wrote a tiny perl script to find all needed files and copy them appropriately. On the command line just specify two directories, which you know are the same, but which arch considers different. If any of the files weren’t copied, you’ll get their names in the warning. When script finishes, you’ll get the total count of copied files.

The script is here: fix_arch_ids.pl

→ 2 CommentsTags: , , , ,

Recursively adding files and directories in Gnu Arch

Posted in All on June 3rd, 2005 · 1 Comment

One of the little annoyances of Gnu Arch is that it does not add files and directories recursively. Not to worry, though. Here is a little shell script that can assist with that task:

#!/bin/bash

# Find all files and directories, skipping ./{arch}
for FILE in `find . -path './{arch}' -prune -o -print`
do
        # Get rid of the leading ./
        FILE=`echo $FILE | sed -e 's/\.\///'`
        tla add "$FILE"
done

Skipping the script itself is left as an exercise to the reader.

Update: Simplier method indeed is

tla inventory --source --names | xargs tla add

→ 1 CommentTags: , , ,

MRTG

Posted in All on April 26th, 2004 · 13 Comments

MRTG (Multi Router Traffic Grapher) is monitoring utility, which runs on many platforms and is capable of collecting and graphing statistical information such as network traffic, CPU/Memory/Disk space usage, etc. MRTG can gather information using both SNMP protocol and external scripts. Below are few pieces of my MRTG config file together with scripts, which I felt like sharing.

[Read more →]

→ 13 CommentsTags: , , , , , , , , , , , , , , , ,