My own patterns :-)

Read a value from DB in a shell script

 # Get time_start, time_end from call_cdr                                                                      
    TIME_START=                                                                                                   
    Q1=/tmp/bundleRec.$GCONFID.ts.sql                                                                             
    echo "select time_start from call_cdr where g_conf_id='$GCONFID' and call_type='CALL_CONF'" > $Q1             
    TMP_LIST=(`mysql --column-names=0 -u $DBUSER -p$DBPASSWORD $DBNAME < $Q1`)                                    
    if [ $? -ne 0 ]; then                                                                                         
        echo "ERROR: Determining time_start from DB failed for gConfId=$GCONFID"                                  
        exit 1                                                                                                    
    fi                                                                                                            
    TIME_START=${TMP_LIST[0]}                                                                                     
    if [ "X$TIME_START" == "X" ]; then                                                                            
        echo "ERROR: time_start could not be determined for gConfId=$GCONFID."                                    
        exit 1;                                                                                                   
    fi                                                                                                            
    rm -f $Q1            

Date arithmetic in the shell

[prompt]# T1=`date -d "2009-07-17 15:36:51" +%s`
[prompt]# echo $T1
1247825211
[prompt]# echo (( $T1 + 3 ))
-bash: syntax error near unexpected token `('
[prompt]# echo $(( $T1 + 3 ))
1247825214
[prompt]# T2=$(( $T1 + 3500 ))
[prompt]# echo $T2
1247828711
[prompt]# date -d "$T2"
date: invalid date `1247828711'
[prompt]# date -d "@$T2"
Fri Jul 17 16:35:11 IST 2009
[prompt]#