Tuesday, January 18, 2011

Mysql regex query

Mysql supports regexes into their queries - this is how you would do it.

desc PENDING_ORDER

+-------------+--------------+------+-----+---------+-------+
| Field       | Type         | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| CustomerID  | varchar(255) | NO   | PRI | NULL    |       | 
| DateCreated | datetime     | NO   |     | NULL    |       | 
| XML_DATA    | text         | NO   |     | NULL    |       | 
| Status      | varchar(20)  | NO   |     | NULL    |       | 
+-------------+--------------+------+-----+---------+-------+

-- find all values that have a new line after the last digit 
 
select XML_DATA as xml from PENDING_ORDER  where XML_DATA REGEXP '[0-9]+\n';

-- Output

< property>
< name> PartnerCustomerID </name>
< value> 999999579
                        </value>
</property>


Monday, January 17, 2011

rotate nohup out file (nohup.log)

I got this article by posting on serverfault.com on how to rotate the nohup log file.
Basically you connect the output of nohup to a pipe that is redirecting to a file - then the file can me moved around very easily.

mknod /tmp/mypipe p
cat < /tmp/mypipe >/tmp/myreallog
nohup myapplication >/tmp/mypipe


To rotate the log:
mv /tmp/myreallog /tmp/rotatedlog
kill [pid of the cat process]
cat < /tmp/mypipe >/tmp/myreallog