Tuesday, June 18, 2013

Bash command to convert string in variable to uppercase


Suppose you have a variable MY_VAR with value: 

MY_VAR="this is my test"

To convert it to uppercase simply use the ^^. For e.g.,  

echo ${MY_VAR^^}

This will output: THIS IS MY TEST

Monday, June 10, 2013

How can i determine what a soft link points to?

Given a file of arbitrary name, here is how you can determine what it links to, when the link destination can also have arbitrary contents: 

readlink -f <linkname>

How to filter only the first Row of awk Output?



For e.g., I need the ping output of where a particular dns resolves to. The problem is I get 2 lines of same text to where this DNS is getting resolved. I need to filter this so that I get just a single line. 

`ping -t 1 abc.mydomain.com | grep "elb." | awk ' { print $2 } '`

The above command outputs 2 lines of same text.. 

mylb.elb.amazonaws.com
mylb.elb.amazonaws.com

To overcome this problem, i modified this to: 

`ping -t 1 abc.mydomain.com | grep "elb." | awk ' { print $2; exit(0); } '`


Sunday, June 9, 2013

Problem with MySql Replication: Last_Errno: 1580 Last_Error: Error 'You cannot 'ALTER' a log table if logging is enabled' on query. Default database: 'mysql'.q


Still don't know the root cause.. but here is how to fix it:

STOP SLAVE;
SET GLOBAL slow_query_log = 'OFF'; SET GLOBAL sql_log_bin = 0;
START SLAVE;

ERROR 1201 (HY000): Could not initialize master info structure

Getting errors on the slave with mysql replication: 

ERROR 1201 (HY000): Could not initialize master info structure

Couple of things to try and fix this issue: 

1.  Try "reset slave" and again try the Change command which should be like: 

CHANGE MASTER TO MASTER_HOST='10.x.x.x', MASTER_USER='repl', MASTER_PASSWORD='slave_password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=0;
mysql> START SLAVE;
2. Check if /etc/mysql/my.cnf have the server-id properly set for both master and slave machines. For both master and slave's server-id should be different.
3. If you are setting up multiple slaves, make sure that all the slaves have different server-id's. 

Erros with mysql. stop: Rejected send message, 1 matched rules; type="method_call",

Getting this error when restarting tomcat with following command: 

sudo service mysql restart

Tried below instead and that worked: 

sudo /etc/init.d/mysql restart


Friday, June 7, 2013

elb-describe-lbs: Malformed input-Malformed service URL: Reason: Connection refused -


Reason: 

Because your machine is not allowed to make a connection/request to 
https://elasticloadbalancing.amazonaws.com

Or there is a temporary network problem. 

How to reload variables from /etc/environment without re-logging in?

source /etc/environment in bash works for program run through terminal, but running programs through shortcuts at GUI does not work. For that you will have to relaunch those programs from terminal after having done source /etc/environment