“Multithreading” with Bash script

Actually is not Multithreading, but the ability to run scripts in parallel and synchronization also ;)

In Linux systems each process has an associated “process identification number” (PID) that you can monitor using the “ps” application. If you want to run a process in background you just need to append the caracter “&” to the command and it will free the console for you.

So basically the script below, executes commands, gathering all PIDs and in the end it waits for them to finish:

#!/bin/bash

function jobidfromstring()
{
local STRING;
local RET;

STRING=$1;
RET=”$(echo $STRING | sed ‘s/^[^0-9]*//’ | sed ‘s/[^0-9].*$//’)”

echo $RET;
}
runmultitask()
{
JOBLIST=””
TASKLIST[0]=””
i=0

for TASK in “$@”
do
$TASK &
LASTJOB=`jobidfromstring $(jobs %%)`
JOBLIST=”$JOBLIST $LASTJOB”
TASKLIST[$i]=$TASK
i=$(($i+1))
done

i=0
for JOB in $JOBLIST ; do
wait %$JOB
echo “${TASKLIST[$i]} – Job $JOB exited with status $?”
i=$(($i+1))
done
}

runmultitask “your parallel” “your parallel”

Running symfony task using bash script

I’m working in a project that uses a lot of symfony tasks to migrate an ancient database to a new one.
Due to some PHP garbage collection issues, we had to do some tricks so the script would run completely . This was done, using a bash script that was responsible to call symfony tasks one at a time, avoiding memory leaking from PHP.

In the script header I’ve put this:

#!/bin/bash
path=”/var/www/palcomigrator”
php=”/usr/bin/php”
symfony=”${php} ${path}/symfony”

runtask()
{
for TASK in “$@”
do
$symfony $TASK
done
}

Here I’ve put the project path location (variable “path”), the php location (variable “php”) and the symfony script location path (variable symfony). I’ve also created an function that is responsible to run a symfony task called “runtask()”.

Now If I wanted to run the symfony task’s “migratePhotos” and “migrateComments” I would create an script like this:

#!/bin/bash
path=”/var/www/palcomigrator”
php=”/usr/bin/php”
symfony=”${php} ${path}/symfony”

runtask()
{
for TASK in “$@”
do
$symfony $TASK
done
}

runtask migratePhotos migrateComments

My First experience with JavaFX

Today I’ve decided that I was going to test JavaFX in my Ubuntu desktop, so I’ve downloaded NetBeans 6.5 (“The official IDE for JavaFX development.”).
I went to “Tools/Plugins” and choose to install JavaFX1.0 and pressed “Install”. The response that I got from NetBeans were:

NetBeans 6.5 JavaFX
NetBeans 6.5 JavaFX

“No plugin providing the capability javafx.sdk could be found”

Unfortunately I couldn’t test JavaFX today :(

How to view only unread messages in GMail

This was something that have been bothering me for a long time, since I’ve some unread messages but I didn’t knew how to find them.
Finally I’ve decided to google “gmail feature request”, and the 5th hit says “Gmail feature request – show unread messages first;)
So, basically you put “label:unread” in the search box and you get all the unread messages :)

Daniel Botelho