Author: k7

  • SSMTP, Crontab gotchas

    I had a few cron entries that did not run and for a long a time I had no idea why. I had the MAILTO variable set at the top of the crontab and I was expecting to be mailed the output of the cron entries. I was surprised when that did not happen. Looking…

  • Using GNU grep to output just the match(es) and not the entire line containing the match(es)

    echo “hello there.” | grep -o “ello t” ello t The flag ‘o’ (not Zero) does the trick. From the man page: -o, –only-matching Show only the part of a matching line that matches PATTERN. I couldn’t find that flag as an option in the BSD Grep man page. So this might only be available…

  • PHP, MongoDB, findAndModify

    findAndModify is not supported by the current version of the PHP MongoDB driver, so I had to use the following code $feed = $db->command(array(‘findAndModify’ => ‘feedList’, ‘query’ => array(‘$where’ => new MongoCode(‘ function(){ return ((this.inProgress == false) || (currentTime >= (this.lastUpdated + this.updateFrequency)))); }’, array(‘currentTime’ => $start))), ‘update’ => array(‘$set’ => array(‘inProgress’ => true)))); Where:…

  • GNU sed, replace search string with contents of a file

    Say, I want to replace the text “replace me” in all the .txt files in the current directory with the contents of modified.js file find . -name “*.txt” -print0 | xargs -0 sed -i -e ‘s/replace me/cat modified.js/e’ Notice the ‘/e’ at the end and that seems to do the trick.

  • jQuery empty(),remove() and Thickbox

    I am a great fan of thickbox and I have used it for a long time. Recently I came across a situation where trying to close a modal that had a table with around 7000 rows (each 8 columns) crashed the tab in Chrome and took a very long time in Firefox. I went through…

  • Unix find, xargs and basename.

    Xargs is great. If you want to know why use xargs over exec, have a read of this: xargs versus exec. But, there is one problem. If the command that you are trying to execute on the results from find cannot take more than one file as param (basename for e.g, can take only one…

  • Munin: Could not open required defaults file: /root/.my.cnf

    For some reason I kept getting this error (even when the file was readable by all) in one of the munin (mysql slave) plugins that I had written. So this was the solution that worked for me; under the [mysql*] section in /etc/munin/plugin-conf.d/munin-node I added this: env.mysqlopts -u{user} -p{password} and in my plugin I did…

  • Fixing: “unknown terminal type” in shell

    Assuming you are using bash Add the following to ~/.bash_profile TERM=vt100 export TERM and then from shell source ~/.bash_profile Note: ‘vt100’ could be replaced with something similar in /usr/share/terminfo/

  • MySQL KEY, PRIMARY KEY and NOT NULL.

    Have a look at this sql statement: mysql> CREATE TABLE `t1` (`id` INT NULL AUTO_INCREMENT, KEY(`id`)); Query OK, 0 rows affected (0.92 sec) mysql> SHOW CREATE TABLE `t1`; +——-+————————————————————————————————————————-+ | Table | Create Table | +——-+————————————————————————————————————————-+ | t1 | CREATE TABLE `t1` ( `id` int(11) NOT NULL AUTO_INCREMENT, KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 |…

  • Q&A Site covering Religion and Philosophy

    I have now been hosting a Q&A site covering 2 of my favorite topics: Religion and Philosophy. Link: bayankaram.com. The name “bayankaram” refers to the legendary Sri Prativadi Bhayankaram Annan Swami who composed Suprabhatham.