How to add a new user to a vsftpd server

Assuming that you already have the vsftpd installed and configured, to create a new ftp user with an home directory you just need to use this commands.

The first thing you need  to do is to create an FTP root directory:

# mkdir <path_directory>

Then you should create an user and make the <path_directory> the user’s home directory:

# useradd -d <path_directory> <ftp_new_user>

Then add a password to the newly created user

# passwd <ftp_new_user>

Add <path_directory> permissions:

# chown <ftp_new_user> <path_directory>

# chmod 0744 <path_directory>

Restart the server:

# /etc/init.d/vsftpd restart

And it’s done!

Now you can access to this ftp account using the <ftp_new_user>

Revert modifications from a git project in Eclipse IDE

Something that I’ve missed when I switch from SVN to git was subeclipse:(

I’m using eGit, but it lacks support for doing a simple task like reverting modifications from a specific file.

eGit without reverting
eGit without reverting

Even though I’m getting use to those simple command line scripts a simple thing like reverting modifications from a specific file is kind of tedious, and this is something that I could handle in the IDE.

To simplify this procedure I’ve created a simple bash script (revert.sh):

#!/bin/bash
# @author Daniel Botelho <botelho.daniel@gmail.com>
# @date 2010-05-19
workspace_loc=$1
project_name=$2
selected_resource_path=$3
git=/usr/bin/git
cd $workspace_loc/$project_name
#echo $git status

#$git status

length=”${#project_name}”+2;
echo $git checkout ${selected_resource_path:length}
$git checkout ${selected_resource_path:length}
echo “completed.”

Then I’ve created a new External Tool Configuration to call this simple script (Run>External Tools> External Tools Configurations…>)

new_ext

Screenshot-External Tools ConfigurationsHere you should change your “Location” to the location where you have your “revert.sh” script.

Ok, and it’s done! :)

Now I can choose the file that I want to revert and click on “Run revert modifications (git)” right from the eclipse IDE.

run

WordPress permalinks format in Goddady.com

If you have an wordpress hosted at Goddady.com, you can’t use permalinks formated out-of-the-box.
Anyway, you can fix this, by editing your “.htaccess” file this way:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /enl/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /enl/index.php [L]
</IfModule>

# END WordPress

Now you can format your permalinks as you want :)

Ubuntu beep for console

If you need to run alot of scripts in your console you’ll find that it’s terrible to wait for those scripts to finish.
I’ve found the “beep” application that allows you to send a sound signal when you run “beep” in the console. With this application I no longer need to stare at the console waiting for that script to finish, because when the script finishes you’ll receive a system beep sound.

So lets say I want to run the script “backup.sh” and receive a beep signal when the script finishes:

$ ./backup.sh ; beep

To install the beep application in ubuntu just run this command in the console:

$ sudo apt-get install beep

“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

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