piwik

dimecres, 5 de juny del 2013

Sed hacks.

How to remove empty lines from a file:
sed '/^$/d' file.txt
Remove commented lines from a specific file
sed 's/^#.*//' file.txt
Above command will replace # 'ed lines by empty lines, in case we want to merge both steps into a single command, we'll issue the following command.
sed -e 's/^#.*//;/^$/d' file.txt

MySQL commands

==========================
Backup database using dump
==========================
1.- Backup
mysqldump -u root xcms > new-xcms.sql

2.- Restore
(Make sure we have created the corresponding database)
mysql -u root -proot xcms < new-xcms.sql

3.-Rename DB
---------------
mysql -e "CREATE DATABASE \`new_database\`;"

for table in `mysql -B -N -e "SHOW TABLES;" old_database`
do
  mysql -e "RENAME TABLE \`old_database\`.\`$table\` to \`new_database\`.\`$table\`"
done
mysql -e "DROP DATABASE \`old_database\`;"
----------------



4.-Create DB
create database old_xcms;

5.- Backup triggers and stored procedures
mysqldump -u root --all-databases --triggers --routines -d -t > dbMasterProc.sql

6.- Create user and grant all privileges
mysql> create user 'root'@'172.16.%';
mysql> grant all privileges on *.* to 'root'@'172.16.%';
mysql> show grants;
+--------------------------------------------------+
| Grants for root@172.16.%                         |
+--------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.%' |
+--------------------------------------------------+
1 row in set (0.00 sec)

7.- Skip execution of one row in replication servers:
mysql> set global sql_slave_skip_counter = 1;

############
Show columns
############
mysql> show columns from tbl_gamechat;
+----------------+----------------------+------+-----+---------+----------------+
| Field          | Type                 | Null | Key | Default | Extra          |
+----------------+----------------------+------+-----+---------+----------------+
| GCHT_iID       | int(10) unsigned     | NO   | PRI | NULL    | auto_increment |
| GCHT_TLST_iID  | int(10) unsigned     | NO   | MUL | 0       |                |
| GCHT_GAM_iID   | int(10) unsigned     | NO   | MUL | 0       |                |
| GCHT_PLY_iID   | int(10) unsigned     | NO   | MUL | 0       |                |
| GCHT_cText     | varchar(255)         | NO   |     |         |                |
| GCHT_dDate     | timestamp            | YES  | MUL | NULL    |                |
| GCHT_iChatType | smallint(5) unsigned | NO   |     | 0       |                |
+----------------+----------------------+------+-----+---------+----------------+

##########
See rows
##########

mysql> select * from tbl_gamechat where GCHT_iID='24875';
+----------+---------------+--------------+--------------+------------+---------------------+----------------+
| GCHT_iID | GCHT_TLST_iID | GCHT_GAM_iID | GCHT_PLY_iID | GCHT_cText | GCHT_dDate          | GCHT_iChatType |
+----------+---------------+--------------+--------------+------------+---------------------+----------------+
|    24875 |          1148 |       756640 |      1029050 |            | 2013-02-19 12:31:03 |              0 |
+----------+---------------+--------------+--------------+------------+---------------------+----------------+
1 row in set (0.00 sec)

##########
Delete row
##########

mysql> delete  from tbl_gamechat where GCHT_iID='24875';

dimarts, 4 de juny del 2013

Usefull hacks for grep command.

How to count the number of lines that match with a specific pattern in a file:
grep -c Josep /etc/passwd
Using -v option, we'll be inverting the results. The number of lines that do not match the pattern will be shown.
grep -cv Josep /etc/passwd
Ignoring case sensitive:
grep -i josep /etc/passwd

Searching through all subdirectories the files that inside them have at least one occurrence of the pattern.
grep -r mysql /home/josep

divendres, 31 de maig del 2013

Setting up external monitor as a primary with Ubuntu, GNOME

Since I am currently working with an ultrabook, which has a very tiny monitor, I attached an external one. So, if we want to get it working as a primary monitore, where the menu bar and the buttons will be displayed, we just have to issue the following command:

xrandr --output VGA-0 --primary

In my case the external monitor is named VGA-0, but you might have different name for it, all you have to do is TAB after xrandr --output and it will prompt you for the different options you have.

Source: http://alt236.blogspot.com/2012/01/setting-up-second-monitor-as-primary.html

dimarts, 28 de maig del 2013

Monitoritzar Gluster 3.2 amb Zabbix

Per la informacio que he trobat, crec que amb la versio 3.2 sols tenim disponible dos comandaments per a monitoritzar l'estat dels volums i la connectivitat amb els "peers". Per tant, aci vos deixe els dos comandament que he afegit a Zabbix.

Amb aquest primer, el que fem es agafem l'estat del volum i imprimim un "1" si es "Started" o un "0" per a la resta de casos.

#Monitoring GlusterFS
UserParameter=glusterfs.status,sudo gluster volume info | grep Status | awk '{print $2}' | sed "s/\s//g" | sed "s/Started/1/" | awk '{ if ($1 == 1) print $1; else printf "0\n" }'



Aci el que fem es comprovar que tots els "peers" estan connectats al volum del server en el que executem Gluster. "1" en el cas que estiguen, "0" per a la resta
 
UserParameter=glusterfs.peer,sudo gluster peer status | grep State | awk '{print $5}' | sed 's/(//g' | sed 's/)//g' | sed "s/\s//g" | paste -sd " " | awk '{ if ($1 == "Connected" && $2 == "Connected" && $3 == "Connected") print "1"; else print "0"}'

dimarts, 21 de maig del 2013

How to install Oracle VM VirtualBox Extension Pack

USB 2.0 is currently enabled for this virtual machine. However, this requires the Oracle VM VirtualBox Extension Pack

This is the message we get when trying to enable USB 2.0 support from Virtual Box. Everything we need to do is go to the following link, and download the package shown bellow.

VirtualBox 4.2.12 Oracle VM VirtualBox Extension Pack  All supported platforms

https://www.virtualbox.org/wiki/Downloads

How to enable USB to the virtual machines on Virtual Box

This is the error we get when we want to go to "Settings".
VirtualBox is not currently allowed to access USB devices. You can change this by adding your user to the 'vboxusers' group

We just need to issue the following command in order to add the current user to vboxusers group.

sudo usermod -aG vboxusers josep

Where "josep" is our current user.
Right after that, we'll need to log out and log back in to see the changes applied.