Friday, May 29, 2015

Changing mouse button settings

I have a wireless mouse which works partially.  When I say partially the left click alone does not work in it.  It could be due to the fact that it was used for many years.  However other aspects of the mouse works, like the scroll wheel, middle click, right click and the pointer moves smoothly across the screen.

The GUI based mouse setting in ubuntu could only allow you to choose between a right handed mouse or a left handed mouse.  I wanted more, I wanted the ability to say what button was left click and what button was right click.  The idea was I need to make my middle click act as left click.  If this could be accomplished I could again have a working mouse with left, right click and scroll wheel.

The site mentioned below [1] came to the rescue.

[1]
https://wiki.ubuntu.com/X/Config/Input

This pictures shows that when I try to reterive the button settings for my mouse it shows 1 2 3 4 all the way up to 13.  We are interested in 1 2 and 3 which corresponds to Left, Middle and Right.

So in the next xinput set-button-map command I replaced 1 2 3 with 1 1 3.  So this effectively made my left button and middle button do the work of left click.


Thursday, May 28, 2015

Small bash script - Chennai Power Outage check

This is a small script which will check if there is power outage in your are and drop you an email a day before.


http://pastebin.com/6xZaB8nb

#!/bin/bash

if [ -f /var/scripts/powercut.txt ]
  then
    rm /var/scripts/powercut.txt
fi

if [ -f /var/scripts/Tomorrow.txt ]
  then
    rm /var/scripts/Tomorrow.txt
fi

wget http://livechennai.com/powercut_schedule.asp -O /var/scripts/powercut.txt

NextURL=`grep "Power shutdown areas" /var/scripts/powercut.txt  | head | grep --color "href" | head -n1 | grep -P -o href.+ | cut -d\" -f2 | sed 's/^/http:\/\/livechennai.com\//'`


EmailSubject=`grep "Power shutdown areas" /var/scripts/powercut.txt  | head | grep --color "href" | head -n1 | grep -P -o title.+ | cut -d\" -f2`


echo "Power shutdown areas in Chennai on 30-05-15" | sed -e 's/^/NO /' -e 's/areas in Chennai/in your area/'

echo $NextURL

echo $EmailSubject

wget $NextURL -O /var/scripts/Tomorrow.txt

powercutyes=`grep -i "Your Street name" /var/scripts/Tomorrow.txt | wc -l`

echo

echo "From: \"SenderFirstname Lastname\" " > mail.txt
echo "To: \"RecepientFirstname Lastname\" " >> mail.txt

if [ $powercutyes -gt 0 ]
  then
    echo "We have power cut tomorrow"
    EmailSubject=`echo $EmailSubject | sed -e 's/^/YES /' -e 's/areas in Chennai/in your area/'`
    echo "Subject: $EmailSubject" >> mail.txt
    grep -i "Your Street name" Tomorrow.txt >> mail.txt
    curl --url "smtps://smtp.gmail.com:465" --ssl-reqd --mail-from "sender@gmail.com" --mail-rcpt "recepient@gmail.com" --upload-file /var/scripts/mail.txt --user "sender@gmail.com:senderGmailPassword"
  else
    EmailSubject=`echo $EmailSubject | sed -e 's/^/NO /' -e 's/areas in Chennai/in your area/'`
    echo "Subject: $EmailSubject" >> mail.txt
    echo "We don't have power cut tomorrow"
    curl --url "smtps://smtp.gmail.com:465" --ssl-reqd --mail-from "sender@gmail.com" --mail-rcpt "recepient@gmail.com" --upload-file /var/scripts/mail.txt --user "sender@gmail.com:senderGmailPassword"
fi

Monday, May 25, 2015

WiFi Keyboard cleaning

I assume/take no responsibility if you killed your keyboard.

Try to rotate the batteries in its slot to fix any contact issues between the batteries and the battery holder metal leads.







Thursday, April 23, 2015

Mysql Master-Master Replication

This site[1] though me how to do the replication.

[1]
https://www.digitalocean.com/community/tutorials/how-to-set-up-mysql-master-master-replication

Steps
MasterA (192.168.56.110)
MasterB (192.168.56.111)
1
# yum install mysql-server mysql-client vim ntpdate
# yum install mysql-server mysql-client vim ntpdate
2
# ntpdate ntp.org
# ntpdate ntp.org
3
# service mysqld restart
# service mysqld restart
4
# /usr/bin/mysqladmin -u root password 'mapass'
# /usr/bin/mysqladmin -u root password 'mbpass'
5
# vim /etc/my.cnf
#--------------------------------------
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

server-id              = 1
log_bin                = /var/log/mysql/mysql-bin.log
binlog_do_db           = example
bind-address           = 192.168.56.110

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#--------------------------------------
# mkdir -p /var/log/mysql/
# chown mysql /var/log/mysql/
# service mysqld restart
# vim /etc/my.cnf
#--------------------------------------
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

server-id              = 2
log_bin                = /var/log/mysql/mysql-bin.log
binlog_do_db           = example
bind-address           = 192.168.56.111

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#--------------------------------------
# mkdir -p /var/log/mysql/
# chown mysql /var/log/mysql/
# service mysqld restart
6
# netstat -antlp | grep 3306
tcp 0 0 192.168.56.110:3306 0.0.0.0:* LISTEN      1655/mysqld
# netstat -antlp | grep 3306
tcp 0 0 192.168.56.111:3306 0.0.0.0:* LISTEN      1558/mysqld
7
# mysql -u root –p
Mapass

8
mysql> show databases;

mysql> create user 'replicator'@'%' identified by 'rapass';
Query OK, 0 rows affected (0.00 sec)

mysql> grant replication slave on *.* to 'replicator'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> show master status \G;
            File: mysql-bin.000001
        Position: 341
mysql>

9
We have to use the mysql-bin.000001 and position of 341 over there in masterB server.
mysql> show databases;

mysql> create user 'replicator'@'%' identified by 'rbpass';
Query OK, 0 rows affected (0.00 sec)

mysql> grant replication slave on *.* to 'replicator'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> show master status \G;
            File: mysql-bin.000001
        Position: 341

mysql> slave stop;

mysql> CHANGE MASTER TO MASTER_HOST = '192.168.56.110', MASTER_USER = 'replicator', MASTER_PASSWORD = 'rapass', MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 341;

mysql > slave start;
10
mysql> slave stop;

mysql> CHANGE MASTER TO MASTER_HOST = '192.168.56.111', MASTER_USER = 'replicator', MASTER_PASSWORD = 'rbpass', MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 341;

mysql > slave start;

11
Mysql > \! iptables -I INPUT 1 -p tcp --dport 3306 -j ACCEPT
Mysql > \! /sbin/service iptables save
Mysql > \! iptables -I INPUT 1 -p tcp --dport 3306 -j ACCEPT
Mysql > \! /sbin/service iptables save
12
Mysql > create database example;


13

This should create a DB called example here too.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| example            |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)
14
mysql> create table example.Bala (`id` varchar(10));

15
mysql> show tables in example;
+-------------------+
| Tables_in_example |
+-------------------+
| Bala              |
+-------------------+
1 row in set (0.00 sec)
mysql> show tables in example;
+-------------------+
| Tables_in_example |
+-------------------+
| Bala              |
+-------------------+
1 row in set (0.00 sec)
16
The following command will takeout Bala table from example DB on both the servers.
mysql> DROP tables example.Bala;
Query OK, 0 rows affected (0.00 sec)

Monday, October 20, 2014

Changing Timezone in Wireshark

Hi

I don't think there is an outright method in wireshark to do it.  However you can set you TZ to some other value as described in this link  http://seclists.org/wireshark/2011/Oct/402


Get the list of TZ from here http://en.wikipedia.org/wiki/List_of_tz_database_time_zones


Now start wireshark like so to start displaying Time in EST.  Note this works in GNU/Linux OS.  Not sure about other OS.

$ TZ='America/New_York' wireshark &



Friday, October 3, 2014

Ubuntu not discovering other OS on my friends computer

I got burned by Ubuntu not discovering other OS on my friends computer.  I found the answer in the link shown below.


http://askubuntu.com/questions/11916/how-to-restore-windows-xp-menu-entry-in-grub




All we need to do is include the following five lines under /boot/grub/grub.cfg #40 custom OS detections......





As always try to take backup before you screw up something real bad.

menuentry "Some Operating System (on /dev/sda1)" {
    insmod ntfs
    set root='(hd0,1)'
    chainloader +1
}