Cron Singleton

Fri 03 July 2015 by Godson

Many times we have to run some tasks periodically. 'Cron' is Linux utility intended for such taks.

Now consider following scenario.

You'r performing one non-deterministic task for every 5min using cron utility. And at one point, time to finish a task exceeds 5 min. What will happen in this case ? Another instance of task will be created. In worst case scenarios, there will be hundreds of instances of same task running, ultimately crashing system. To avoid such events, use cron singleton. This singleton ensures that at a time only one instance of taks will be running. Following is example of such singleton.

#!/bin/bash

lockfile=/var/tmp/bamlock

if ( set -o noclobber; echo "$$" > "$lockfile") 2> /dev/null; then
    trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
    # run job
    /opt/foo/bar/baz/qux.py
else
    echo "Lock Exists: $lockfile owned by $(cat $lockfile)"
fi

Cookie blocked in Iframe for Internet Explorer

Sat 27 June 2015 by Godson

When working with chat application recently which uses user sessions, IE is not saving the cookies. This happens when your webpage gets embedded into an iFrame.

Scenario

Lets say we have two websites example.com and anotherexample.com. Now, in anotherexample.com I have an iFrame SRC="http://example.com ...

read more

Coloring Shell Output

Mon 22 June 2015 by Godson

Coloring Shell

read more

How to blink browser tab

Mon 15 June 2015 by Godson

Have you ever wanted to blink/flash browser tab on certain activity ?

Here is a scenario : Suppose there's a chat application installed on your website. Now what if the user of your website is having multiple tabs opened in his browser and there is an incoming message? How will ...

read more