Add a small command line tool to get information about a user.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 10 Nov 2007 15:12:49 +0000 (16:12 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 10 Nov 2007 15:12:49 +0000 (16:12 +0100)
Just run ./getuser.sh "fields" "Name" ["promo"] eg.:
./getuser.sh user_id "F B" 2003 will output

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
bin/getuser.sh [new file with mode: 0755]

diff --git a/bin/getuser.sh b/bin/getuser.sh
new file mode 100755 (executable)
index 0000000..30e6377
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+field=$1
+nom=$2
+promo=$3
+
+query="SELECT $field FROM auth_user_md5 AS u "
+where=""
+pos=0
+for i in $nom ; do
+  query="$query INNER JOIN search_name AS sn${pos} ON (u.user_id = sn${pos}.uid) "
+  [ "$where" != "" ] && where="$where AND"
+  where="${where} sn${pos}.token LIKE \"${i}%\""
+  pos=$((pos + 1))
+done
+if [ "${promo}" != "" ] ; then
+  [ "$where" != "" ] && where="$where AND "
+  where="${where} u.promo = $promo"
+fi
+query="${query} WHERE ${where} GROUP BY u.user_id"
+
+echo $query | mysql --default-character-set=utf8 -N x4dat