Mysql Database creation script

Two days ago one of my client dev’s requested me to be able to create db’s on their MySQL instance.
Of course, I won’t give him the “GRANT GRANT WITH GRANT OPTION” :-P, in that case I will simply give him root password :-P
As i didn’t find anything that solves my problem over Internet, I just did mine, as allways..
Here’s he result.

Prereqs:

  • Create a Mysql user with the following grants:
    [cc lang=”bash”]
    GRANT CREATE, RELOAD, SHOW DATABASES, CREATE USER ON *.* TO ‘database_creator’@’localhost’ IDENTIFIED BY ‘YOUR_PASSWORD’ ;
    GRANT INSERT ON `mysql`.`db` TO ‘database_creator’@’localhost’ ;
    [/cc]
  • That will allow us to create databases, users, make some checks and reload privs, while we don’t create a new “root”…

You can download the script code from the wiki, also you’ll find additional information there.

Follow and Share!!
Regexp mortal

Hoy realizando una tarea que va a ser repetitiva (MODO CRON ON), he tenido que currar una regexp, la verdad no es muy compleja en sí pero sí larga:

'/(project|production)/production/(hs|ga)[0-9]{2}/Runs/[0-9]{6}_SN[0-9]{3}_[0-9]{4}_[0-9A-Z]{8}XX/(Data/Intensities/(L00[0-9]/C*|BaseCalls/L00[0-9]/C*)|Thumbnail_Images/L00[0-9])'

Cuanto tardará find en procesar algo como esto con una jerarquía de unos 36000K ficheros xD
Respuesta en breve :-)

Follow and Share!!
El típico día a día

Hoy un amigo me planteaba un problema.
Resulta que tiene 2 ficheros con datos del tipo:

  • fichero1: [SERIAL]|[ID], por ejemplo:
    8944110064809868270|1221174
  • fichero2: [ID], por ejemplo:
    1185648

El problema es sencillo, necesita mostrar del fichero1 [SERIAL]|[ID] si [ID] está en fichero2 y de los que no estén en fichero2 mostrar únicamente la ocurrencia con [ID] más alto.
La cuestión es que todos los [ID] de fichero2 están en fichero1.

Después de un buen rato, opté por ignorar fichero2, total, todos los datos están en fichero1, no nos da ningún dato significativo.
Y lo que obtuve fue lo siguiente:
sort -k 2 -n -t "|" fichero1.txt | awk -F\| '{
file1array[$1] = $2
} END{
for (SSN in file1array)
print SSN"|"file1array[SSN] }' > test.file

El razonamiento es sencillo teniendo, la clave la da la ordenación del principio, ya que el array que creo dentro de awk irá machacando [ID] menores.

Follow and Share!!
The easiest way to start X

Yesterday while reinstalling Arch in the x86_64 flavour :-) I was thinking which will be the best way to start X window system.
I want to start my X window’s without user prompt (so CDM is not an option), and I don’t any of common login-managers (gdm, xdm, kdm or slim)… I’ve tried to use the simplest way, and it works!

Let’s go, deps:
[cc lang=”bash”]
pacman -Ss xorg-xinit screen
[/cc]
And optional:
[cc lang=”bash”]
pacman -Ss xterm xort-twm
[/cc]
Cool? ;-) Of course, you must have the X-window (1 &2) system installed and your preferred lightweight desktop manager.

Add your super-power-user:
[cc lang=”bash”]
useradd -s /bin/bash -c “super-power-user” dodger
[/cc]

And now the script:
[cc lang=”bash”]
vim /etc/rc.d/autofluxbox
[/cc]
[cc lang=”bash”]
#!/bin/bash -x
LOGDIR=/var/log/autofluxbox
[ ! -d $LOGDIR ] && mkdir $LOGDIR
exec 1> $LOGDIR/autofluxbox.$(date +%Y%m%d%H%M).log
exec 2> $LOGDIR/autofluxbox.$(date +%Y%m%d%H%M).err
USER=dodger
STARTX=”/usr/bin/startx”

su – ${USER} -c “screen -S Fluxbox_startup -d -m ${STARTX}”
[/cc]

And:
[cc lang=”bash”]
chmod +x /etc/rc.d/autofluxbox
[/cc]
One thing I’ve just found is ${PATH} seems to be wrong on my X environment ¬¬’… I will continue investigating.

Follow and Share!!
Strange feature in bash script

Today, while programming (or reprogramming) some parts of one script, I’ve noticed a strange thing.
First, the two scripts.

The working one:

#!/bin/bash
let x=0
echo -e "a\nb\nc\nd" > auxfile
while read LINE
do
[[ "${LINE}" =~ ^(a|c|d)$ ]] && AUX[$x]=${BASH_REMATCH[1]} && let x++
done < auxfile
echo ${AUX[@]}

And the not working (for my purpose):

#!/bin/bash
let x=0
echo -e "a\nb\nc\nd" | while read LINE
do
[[ "${LINE}" =~ ^(a|c|d)$ ]] && AUX[$x]=${BASH_REMATCH[1]} && let x++
done
echo ${AUX[@]}

The only difference between both is just the piped while.
Someone can explain why seems to be a “reset vars” at the end of the piped while?

Follow and Share!!