Daily Archive for July 12th, 2009

GNU make for the win …

I’ve just replaced my little shell script that was helping me to update the hash files inside my postfix configuration. While before I had hardcoded the paths/names, they are now simply fetched by means of find. In addition to the old capabilities, the new make file will also copy any files required inside the chrooted /etc, if they aren’t up-do-date. Since make works by means of timestamps of the targets, this is easily achieved.

Here’s how it looks (stripped the “intro” of the make file, though).

config-files := $(shell find /var/spool/postfix/etc/ -type f)
hash-files   := $(shell find $(CURDIR) -name '*.hash')
hashdb-files := $(addsuffix .db,$(hash-files))

.PHONY: all
all: $(hashdb-files) $(config-files)
    newaliases
    postfix check
    postfix reload

/var/spool/postfix/etc/%: /etc/%
    cp --preserve=timestamps $(patsubst /var/spool/postfix%,%,$@) $@

%.hash.db: %.hash
    postmap $(patsubst %.db,%,$@)
    @chown root:postfix $@ $(patsubst %.db,%,$@)
    @chmod u=rwX,g=r,o= $@ $(patsubst %.db,%,$@)
ifeq ($(filter $(MAKECMDGOALS),all rebuild),)
    postfix check
    postfix reload
endif

.PHONY: info
info:
    -@echo "config-files = $(config-files)"
    -@echo "hash-files   = $(hash-files)"
    -@echo "hashdb-files = $(hashdb-files)"

.PHONY: rebuild
rebuild: clean all

.PHONY: clean
clean:
    -@echo "Cleaning $(CURDIR) ..."
    -@rm -f $(hashdb-files)

You can download it here.

// Oliver

Little changes with big effects …

I’m using screen more and more, but this night I ran into a problem I hadn’t anticipated. I was trying to establish SSH sessions inside “pre-created” windows (using a specific screen profile). Now I wanted to automatically call an initial command once the SSH connection would be established.

Just using screen -t machine ssh machine worked fine (and started the remote shell), but once I used any command (screen -t machine ssh machine command), the remote terminal wouldn’t echo (no prompt, for example) but it would show black/white output of commands I’d run. So clearly the command I had invoked on the remote end was being executed, just something was wrong with the terminal type (among other things).

The solution was interesting though. By adding the -t option I would force SSH to allocate a pty and suddenly it worked.

Like this: screen -t machine ssh -t machine command

// Oliver