Quickly check if a process is running or not

When writting bash scripts one often needs to see if a process is running or not
I like the following code; though I’m sure many ways of doing this exists, what’s your favorite?
[cce_bash]
if [ -z “$(pgrep process)” ]
then
echo “process is not running”
else
echo “process is running”
fi
[/cce_bash]

New AdSense interface language

Though not my native language I like all my software in English. It always sounds weird to me to see it different. Ever since AdSense upgraded the looks it switched to Romanian. Today I wanted to tackle this:

I went to Home->Account settings->Display Language

It was already English US

Well, it won’t be the first webapp displaying a default that was there in the interface but not in the settings database.

So I clicked EDIT switched to English UK, hit save and then back to English US and save again.

It worked. QA was at lunch again for google.

Cisco (Linksys) E3200 router triggers blocked host with DynDNS

I finally had to upgrade my home router from an aging WRT54GL and went (despite missing dd-wrt for now) with the Linksys E3200. I installed yesterday including dyndns support because I sometimes access my home network when away. I was surprised to receive an email from dyndns this morning stating that my host has been blocked because of abuse. It was strange since my connection is stable and even though some routers have flaky dyndns update clients linksys didn’t disappoint me until now…

I do have the latest firmware version so no help there. I browsed a bit around and I found out that others share my issues including owners of the more expensive e4200.

Somebody was brave enough to fight tech support until escalated and got a useful response (I’m pasting the relevant part here):

If you have the DDNS server active, every time you hit the save settings button on ANY page of the router GUI, it refreshes all of the settings – which includes re-updating DynDNS even if the IP address hasn’t changed.

That’s not nice of them, I really hope this will be fixed in a future firmware update. I fiddle with my configuration from time to time and I’m sure next time I’ll forget to disable dyndns before changing settings.

I know that I’m just quoting from a forum but I want a copy of the sollution here, otherwise next time I change the settings I won’t know why my host gets blocked 🙂

flac2mp3 conversion bash script

I recently started buying some music in flac format. Though I’m content on storing it as flac on my NAS I don’t like filling up my phone’s memory and also I have the impression that listening to flac uses more battery on my n900.

So I devised a small script that converts all the flac’s from a folder to mp3. It has some provisions to carry the metadata from one format to the other. It’s based on the one found here, with the following modifications:

  • it encodes as 320kbps stereo (not joint stereo) There’s a whole debate on whether one can hear or not the quality improvement but it’s still less than half the original flac file so I didn’t really care on finding out if I could go lower. Changing the lame parameters is easy enough if you want different output settings
  • instead of id3 it uses id3tag as it’s more current.
  • Dependencies: metaflac, id3tag, lame (use your distro’s package manager to find out which packages provide those binaries)

 

[cce_bash]
#!/bin/bash
for a in *.flac

do
OUTF=`echo “$a” | sed s/.flac$/.mp3/g`

ARTIST=`metaflac “$a” –show-tag=ARTIST | sed s/.*=//g`
TITLE=`metaflac “$a” –show-tag=TITLE | sed s/.*=//g`
ALBUM=`metaflac “$a” –show-tag=ALBUM | sed s/.*=//g`
GENRE=`metaflac “$a” –show-tag=GENRE | sed s/.*=//g`
TRACKNUMBER=`metaflac “$a” –show-tag=TRACKNUMBER | sed s/.*=//g`
DATE=`metaflac “$a” –show-tag=DATE | sed s/.*=//g`

flac -c -d “$a” | lame -m s -b 320 -s 44.1 – “$OUTF”
id3tag -s”$TITLE” -t”${TRACKNUMBER:-0}” -a”$ARTIST” -A”$ALBUM” -y”$DATE” -g”${GENRE:-12}” “$OUTF”

done
[/cce_bash]

BackupPC – can’t find Compress::Zlib

It all started with an update for perl by our lovely CentOS. After that backuppc complained about  Compress::Zlib. I tried installing it from CPAN but it didn’t work: Undefined subroutine &Compress::Zlib::gzopen called.

One proposed fix was to remove everything Zlib related from the perl folder in /usr/lib. It did work, as CPAN started working but Zlib refused to install due to errors.

I finally stumbled to this fix:

Turns out it’s a problem with List::Util. The perl-Scalar-List-Utils
rpm conflicts with perl-5.8.8-32.el5_5.1.i386 rpm. Upgrading List::Util
from 1.19 to 1.23 from CPAN solved the problem.

 

Close enough, but my version of List::Util was up to date. Still it was worth a shot; a force install List::Util in perl CPAN shell (perl -MCPAN -e shell) I was back up and running!

Concatenate multiple *.vcf files into one for importing into gMail

I have a secondary phone that is running Android. My main phone is still a Nokia N900 for which I gave up trying to sync contacts with gmail. Two options basically exist for n900 none of which works for me:

  1. using MFE which works from time to time
  2. use syncevolution which invariably screws my contacts on the n900 (I guess google’s implementation of syncml or exchange support is dubious at best)

So I devised a third. Since I edit and store all my contacts on the n900 I will export them from time to time (Contacts->Export->All contacts)  and import them manually into gmail. Note that Gmail doesn’t support vCard 3.0; you have to export as 2.1. Unfortunately the n900 will export each contact into a separate file. Since google doesn’t offer bulk import support I thought of concatenating all files into one:

cat *.vcf > all_contacts.vcf

Good idea, but it doesn’t work. In another example of fine programming skills clicking import uploads the file and returns with no contact imported and no error message. Nice one.

It seems some new lines are missing; and so this will work (in the folder with the vcf files)

[ccNe_bash]
for i in *.vcf; do cat “$i” >> ../all_contacts.vcf; echo >> ../all_contacts.vcf; done
[/ccNe_bash]
Import worked now ok!

Update:

Here’s courtesy of Adam A Johnson (in the comments below) how to do the same in Windows.
[ccNe_dos]
FOR %f IN (*.vcf) DO TYPE “%f” >> all_contacts.vcf & ECHO. >> all_contacts.vcf
[/ccNe_dos]