Thursday, December 20, 2012

Find files in a particular directory which are older than 30 min

My solution to the following problem:
How can I find files in a particular directory which are older than 30 min? I am not able to use several functions like -mmin, -stat, date -r . And I cant create a dummy file with touch command also,as it is to be done in a production environment.
Posted in: http://unix-simple.blogspot.com/2008/01/awkgawk-shell-script-question_31.html


#!/bin/bash

# Current time in seconds since the EPOCH
CURRENT_TIME=$(date +%s)

# 30 minutes in seconds
OFFSET=$((30 * 60))

# The record delimiter
IFS=$'\012'

# The Linux ls
for LINE in $(ls -l --time-style=+%s)
do
        FILE_TIME=$(echo ${LINE} | sed 's/[ ]\+/ /g' | cut -d " " -f 6)
        FILE_NAME=$(echo ${LINE} | sed 's/[ ]\+/ /g' | cut -d " " -f 7)
        TIME_DIFF=$((CURRENT_TIME - FILE_TIME))

        # Avoiding that annoying total count in ls -l
        if [ -n "${FILE_NAME}" ]
        then
                if [ ${TIME_DIFF} -gt ${OFFSET} ]
                then
                        echo "${FILE_NAME} ${FILE_TIME} ${CURRENT_TIME} ${TIME_DIFF}"
                fi
        fi
done

##END##

Chanukah Menorah

A Chanukah Menorah close to my office.

Wednesday, November 14, 2012

Turn a family's living nightmare into a hopeful dream

This is Siyovle, 7 years: "I like to cook rice because it fills my stomach," he said. "When we have rice, I can share it with my family, and they share with me."

Please be compassionate!

Taken from Food for thePoor: http://www.foodforthepoor.org/

Tuesday, November 13, 2012

Fields of Gold


Eva Cassidy, her beautiful performance of Fields of Gold: http://youtu.be/hKtqTYSOBCg

Monday, November 12, 2012

The Golden Rule Rules!


There is a simple statement in the Bible that is such a powerful principal. In fact, it has been present in every ancient and modern culture, and every religion, and it is foundational in philosophy, psychology, and sociology. That shouldn't be surprising, really, because all truth is God's truth.

You'll recognize it. You probably learned it in kindergarten as the Golden Rule. 

Jesus taught it in Luke 6:31. "Do to others as you would have them do to you."

Another way to look at it is, You reap what you sow.

I grew up in a small Arkansas town named Hope, and there were a lot of farmers in our community. But that wasn't a skill I learned. I couldn't grow my own food if my life depended on it. But I know that a good harvest depends upon good seed. And when you put bad seed in the ground, it produces bad results

The Bible describes the spiritually disobedient this way: 

"They sow the wind and reap the whirlwind. The stalk has no head; it will produce no flour. Were it to yield grain, foreigners would swallow it up" (Hosea 8:7 NIV).

Throughout the Bible, you can read about the principal of sowing and reaping. It's a simple concept that you and I can put into action today. Everybody knows that you can't plant an apple seed and expect to get corn.  If you plant apple seeds you'll get apples. What you sow, you shall reap. 

God teaches us in Hosea that if we plant destructive and negative seeds, destruction and negativity will come back to us. How do we plant those seeds in today's world?  Through our words and actions. 

Every day, we plant seeds for our future harvest. Everything we have in our life today was planted in the seed form from our past. 

But here is the good news of Jesus Christ. It's never too late to change your harvest. Simply start planting and sowing good seeds of love -- in fact the fruits of the Spirit -- today! You'll start seeing results immediately.

The Golden Rule ... rules! 

--- Mike Huckabee

Taken from GodFruits.com


Tuesday, October 30, 2012

Wednesday, October 24, 2012

arping utility in Linux


The arping utility is part of the iputils-arping package in Debian like systems.

It is very useful for finding out if an IP number is already taken in a local network.

The syntax should be:

~$ arping -D -I eth0 -c 3 172.17.12.228
ARPING 172.17.12.228 from 0.0.0.0 eth0
Sent 3 probes (3 broadcast(s))
Received 0 response(s)

No IP in this case.

~$ arping -D -I eth0 -c 3 172.17.12.222
ARPING 172.17.12.222 from 0.0.0.0 eth0
Unicast reply from 172.17.12.222 [00:21:70:6A:EA:48]  0.754ms
Sent 1 probes (1 broadcast(s))
Received 1 response(s)

One IP found.

-D Duplicate  address  detection  mode  (DAD).  See RFC2131, 4.4.1. Returns 0, if DAD succeeded i.e. no replies are received.


Monday, October 22, 2012

Sniffing Tutorial part 2 - Dumping Network Traffic to Disk - NETRESEC Blog

http://www.netresec.com/?page=Blog&month=2011-03&post=Sniffing-Tutorial-part-2---Dumping-Network-Traffic-to-Disk

City of Miami neighborhoods map










http://en.wikipedia.org/wiki/File:Miami_neighborhoodsmap.png

SQLite Tutorial

http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html

How does NTP work?

http://www.ntp.org/ntpfaq/NTP-s-algo.htm

Hurricane Tracker at The Weather Channel

http://www.weather.com/weather/hurricanecentral/tracker

Guide to IP Layer Network Administration with Linux

http://linux-ip.net/html/

Network interfaces in Fedora 14

http://docs.fedoraproject.org/en-US/Fedora/14/html/Deployment_Guide/ch-Network_Interfaces.html

IP Command Reference

http://linux-ip.net/gl/ip-cref/

Sed - An Introduction and Tutorial by Bruce Barnett

http://www.grymoire.com/Unix/Sed.html

Wallpapers

http://interfacelift.com/wallpaper/artist/11731/giovanni_di_gregorio/index2.html

MySQL C# tutorial

http://zetcode.com/db/mysqlcsharptutorial/

Tom's Hardware

http://www.tomshardware.com/

The Joel Test


The Joel Test
  1. Do you use source control?
  2. Can you make a build in one step?
  3. Do you make daily builds?
  4. Do you have a bug database?
  5. Do you fix bugs before writing new code?
  6. Do you have an up-to-date schedule?
  7. Do you have a spec?
  8. Do programmers have quiet working conditions?
  9. Do you use the best tools money can buy?
  10. Do you have testers?
  11. Do new candidates write code during their interview?
  12. Do you do hallway usability testing?

InnoDB ibdata1 never shrinks after data is removed

http://bugs.mysql.com/bug.php?id=1341

Mariel Passengers Database

http://www.miamiherald.com/cgi-bin/mariel/index

Berkeley Packet Filter (BPF) syntax

http://biot.com/capstats/bpf.html

Ip Link

http://linux-ip.net/html/tools-ip-link.html

Add a digital signature to a file or macro project

http://office.microsoft.com/en-us/excel-help/add-a-digital-signature-to-a-file-or-macro-project-HP005249557.aspx?CTT=3

Casio watches manuals

http://world.casio.com/wat/download/en/manual/

Host tuning for different OSes

http://fasterdata.es.net/host-tuning/

Configuring static network routes in Fedora 14

http://docs.fedoraproject.org/en-US/Fedora/14/html/Deployment_Guide/s1-networkscripts-static-routes.html

A tutorial about Log4j. Using appenders. Includes examples.

http://www.mobilefish.com/developer/log4j/log4j_quickguide_appenders.html

Solaris host unable to join multicast groups

An IGMPv2 Membership Request packet is described in RFC 3376.

IGMP messages are encapsulated in IPv4 datagrams, with an IP protocol number of 2. Every IGMP message described in this document is sent with an IP Time-to-Live of 1, IP Precedence of Internetwork Control (e.g., Type of Service 0xc0), and carries an IP Router Alert option in its IP header

The Router Alert option is described in RFC 2113.

The option type field is sub-divided into a one bit copied flag, a two bit class field, and a five bit option number.  These taken together form an eight bit value for the option type field.

Copy Class Number Value Name                            Reference
---- ----- ------ ----- ------------------------------- ------------
1    0     20     148   RTRALT - Router Alert           [RFC2113]


In binary: 1 00 10100

In Solaris 10 an IGMP multicast join packet has the IP options section with an hexadecimal  value of:

00 04 00 00

It should be:

94 04 00 00

In Solaris 10, IGMP V2 membership report packets have a) a RFC non-compliant IP options header and b) the IP options header is unnecessary.

When a multicast router sends an IGMP V2 query (normally having IP option 148 (router alert) set), a Solaris 10 box replies with IGMP V2 reports for all multicast groups the box want to receive.

The IGMP packets generated by Solaris 10 contain an IP option header which is in two respects wrong:

a) as there is no "meaningful" option present (only the option "end of option list", abbreviated EOL or EOOL), there should be no IP option header present in the packet

b) If the option header is still present (because of other IP options), the last four bytes should carry the value "00 01 01 01" instead of value "00 04 00 00" , as the option number 00 means "end of options list", is a one-byte value and should be padded with 01 (NOP).

The bug is fixed in Sun's IDR hotfix 123621-01 (requires kernel patch 118833-18). Afterwards, a Solaris 10 box sends IGMP messages with the correct "router alert" IP option set, thats 94 04 00 00.

References:

RFC2236: http://tools.ietf.org/html/rfc2236
RFC2113: http://tools.ietf.org/rfc/rfc2113.txt
IANA IP Options Numbers: http://www.iana.org/assignments/ip-parameters
https://forums.oracle.com/forums/thread.jspa?threadID=1948503&tstart=345

Thursday, September 27, 2012

Tuesday, September 4, 2012

Windows Firewall from the command line

netsh firewall show state

netsh firewall set opmode mode=DISABLE

netsh firewall set opmode mode=ENABLE exceptions=DISABLE

netsh firewall set opmode mode=ENABLE exceptions=ENABLE

More about it: http://support.microsoft.com/kb/947709

Tuesday, August 28, 2012

Windows uptime


1.  Go to "Start" -> "Run".

2.  Write "CMD" and press on "Enter" key.

3.  Write the command "net statistics server" and press on "Enter" key.

4.  The line that start with "Statistics since …" provides the time that the server was up from.

The command "net stats srv" can be use instead.

Taken from: http://support.microsoft.com/kb/555737

Other possibility: the command systeminfo

And another: net statistics workstation.

Friday, July 6, 2012

How to Initialise a static Map in Java

private static final Map<String, String> channelTypes =
    new HashMap<String, String>();
static {
        channelTypes.put("I", "Incremental");
        channelTypes.put("N", "Instrument");
        channelTypes.put("S", "Snapshot");
}

private static final Map<String, String> channelTypes =
     new HashMap<String, String>() {
     {
                    put("I", "Incremental");
                    put("N", "Instrument");
                    put("S", "Snapshot");
      }
};

Friday, June 29, 2012

MP3 tagging with Perl


#!/usr/bin/perl

use strict;
use warnings;

use MP3::Tag;
use File::Basename;

my $Directory = ".";

while (<$Directory/*.mp3>) {
my ($FileName) = basename($_, '.mp3');

my $Mp3 = MP3::Tag->new($_);

$Mp3->title_set($FileName);
$Mp3->artist_set('Artist');
$Mp3->album_set('Album');
$Mp3->year_set('2012');

$Mp3->update_tags();

print "Filename: $_\n";
print "Artist: " . $Mp3->artist . "\n";
print "Title: " . $Mp3->title . "\n";
print "Album: " . $Mp3->album . "\n";
print "Year: " . $Mp3->year . "\n";
print "Genre: " . $Mp3->genre . "\n";

$Mp3->close();
}

__END__

Friday, June 8, 2012

How do I add the Bloomberg Excel Add-in to Excel?

  1. Open Excel
  2. Go to Tools menu
  3. Select Addins, then Browse
  4. Select: C:\blp\API\Office Tools\BloombergUI.xla
  5. After selecting the add-in the Bloomberg Excel tools should appear checked in your add-ins list. Close the add-ins and the toolbar should appear.

Thursday, May 24, 2012

Five Fridays in July every 823 years == false


package pkg5fridaysinjuly;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {

    private static final int NUMBER_OF_YEARS = 823;

    public static void main(String[] args) {

        Calendar c = new GregorianCalendar();

        int firstYear = c.get(Calendar.YEAR);
        int lastYear = firstYear - NUMBER_OF_YEARS;

        c.set(firstYear, Calendar.JULY, 1);

        System.out.println("Initial: " + firstYear);
        System.out.println("Last: " + lastYear);

        for (int y = firstYear; y >= lastYear; y--) {

            c.set(y, Calendar.JULY, 1);

            if (c.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) {

                System.out.println(y + " Found!");
            }
        }
    }
}

Wednesday, April 25, 2012

Configuring Logging in Glassfish

Calls to System.out.println are logged at the INFO level using the logger name javax.enterprise.system.stream.out. Calls to System.err.println are logged at the WARNING level using the logger name javax.enterprise.system.stream.err. To turn off the logs from these sources, specify the logger name with the value OFF in the Additional Properties area.


Friday, April 20, 2012

The World's Greatest Solvable Problem


The price tag for solving hunger is also less than you may realise:

- US 20 cents: the cost of one super-healthy ration of Plumpy’Sup for a small child, less than the cost of a US postage stamp
- US $10: the costs to feed a boy in a Kenya refugee camp for 3 weeks, less than the cost of a lipstick bought in Manhattan
- US $50: the cost to feed a schoolgirl for one year, roughly the same price for an iPod shuffle
Taken from freerice.com site.

Monday, April 16, 2012

We Animals pictures

Stray dog in Santiago, Chile. I visited this market several times and the dog was always in the same place, lying in his box. 2005.
Taken from: http://www.weanimals.org/photographs.php

Tuesday, March 27, 2012

What Week Day Is That Date in the Past?

A solution for: http://www.linuxjournal.com/content/work-shell-what-day-date-past

No AWK involved.


#!/bin/bash


# We need 3 arguments:
# DOW, Month and Day


if [ $# -ne 3 ]
then
        echo "Usage: $(basename $0) weekday month day"
        echo "(example: $(basename $0) 4 3 2)"
        exit 1
fi


# We use the date command for checking


date -d "$2/$3" &> /dev/null


if [ "$?" == "1" ]
then
        echo "$(basename $0) Error: Invalid date!"
        exit 1
fi


# Month as number
M=$(date -d "$2/$3" +%m)


# The day of the month
D=$(date -d "$2/$3" +%e | sed 's/ //')


WD=$1


# The day of year is gonna help us decide which is
# the first year to test: current year or the previous one
DOY=$(date -d "$2/$3" +%j)
CDOY=$(date +%j)


Y=$(date +%Y)


if [ ${DOY} -gt ${CDOY} ]
then
        Y=$(expr ${Y} - 1)
fi


echo $M $D $WD $DOY $CDOY $Y


F=''
until [ -n "${F}" ]
do
        echo -n $Y $M =


        # The calendar for the month and year
        # Extract the line with the day of the month
        # Add numbers to the lines, the number will be
        # used to identify the Day of the Week
        # Extract the line of the particular day
        # gotta be careful cause 6 1 is the sixth line day 1
        # and 1 6 is the first line day 6, so we search by the second number
        # Convert the multiple spaces in front of the numbers into one space
        # so the cut command always return the second field
        # Extract the first number only, that's the DOW


        CWD=$(cal ${M} ${Y} \

                | grep "\b${D}\b" \
                | sed 's/[ ][ ][ ]\|[ ][ ]\|[ ]/|/g; s/^|//; s/|/\n/g' \
                | cat -n \
                | grep "\b${D}\b$" \
                | tr -s [:space:] ' ' \
                | cut -d ' ' -f 2)


        if [ ${WD} -eq ${CWD} ]
        then
                F=Found
        fi


        echo $CWD


        Y=$(expr ${Y} - 1)
done


##END##

The output of searching the first date in the past when March 1 was Wednesday:

janeiros@harlie:~/tmp$ ./t.sh 4 3 1
03 1 4 061 087 2012
2012 03 =5
2011 03 =3
2010 03 =2
2009 03 =1
2008 03 =7
2007 03 =5
2006 03 =4

janeiros@harlie:~/tmp$ cal 3 2006
     March 2006
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31



AWK documentation

http://sunsite.ualberta.ca/Documentation/Gnu/gawk-3.1.0/html_chapter/gawk.html

Day of the Week in GAWK

gawk '
BEGIN {
  for (d = 1; d <= 31; d++) {
    t = mktime("2008 08 " d " 0 0 0")
    print d, strftime("%A", t)
  }
}'


The output is:

1 Friday
2 Saturday
3 Sunday
4 Monday
5 Tuesday
6 Wednesday
7 Thursday
8 Friday
9 Saturday
10 Sunday
11 Monday
12 Tuesday
13 Wednesday
14 Thursday
15 Friday
16 Saturday
17 Sunday
18 Monday
19 Tuesday
20 Wednesday
21 Thursday
22 Friday
23 Saturday
24 Sunday
25 Monday
26 Tuesday
27 Wednesday
28 Thursday
29 Friday
30 Saturday
31 Sunday

Compare to:
$ cal 8 2008
    August 2008
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

Friday, March 23, 2012

Ubuntu's non persistent network configuration

sudo ip addr add 192.168.1.14/24 dev eth0
sudo ip link set dev eth0 up
sudo ip route add default via 192.168.1.1

Or

ifconfig eth0 192.168.1.14 netmask 255.255.255.0
route add default gw 192.168.1.1 eth0

Tuesday, March 20, 2012

APT and Dpkg Quick Reference Sheet



APT and Dpkg Quick Reference Sheet


Matthew Danish

Common APT usage

apt-get install <package> Downloads <package> and all of its dependencies, and installs or upgrades them. This will also take a package off of hold if it was put on. See below for more info on hold.

apt-get remove [--purge] <package> Removes <package> and any packages that depend on it. --purge specifies that packages should be purged, see dpkg -P for more information.

apt-get update Updates packages listings from Debian mirrors, should be run at least once a day if you install anything that day, and every time after /etc/apt/sources.list is changed.

apt-get upgrade [-u] Upgrades all packages installed to newest versions available. Will not install new or remove old packages. If a package changes dependencies and requires installation of a new package, it will not be upgraded, it will be put on holdinstead. apt-get upgrade will not upgrade packages put on hold (that is the meaning of hold). See below for how to manually put packages on hold. I suggest the `-u' option as well, because then you can see what packages are going to be upgraded.

apt-get dist-upgrade [-u] Similar to apt-get upgrade, except that dist-upgrade will install or remove packages to satisfy dependencies.

apt-cache search <pattern> Searches packages and descriptions for <pattern>.

apt-cache show <package> Shows the full description of <package>.

apt-cache showpkg <package> Shows a lot more detail about <package>, and its relationships to other packages.

dselect
console-apt
aptitude
gnome-apt
 Graphical front ends to APT (some of these may be in their own package, that must be installed before use). While dselect is arguably the most powerful, it's also the oldest and hardest to use.

Common Dpkg usage

dpkg -i <package.deb> Installs a Debian package file; one that you downloaded manually, for example.

dpkg -c <package.deb> Lists the contents of <package.deb>, a .deb file.

dpkg -I <package.deb> Extracts package information from <package.deb>, a .deb file.

dpkg -r <package> Removes an installed package named <package>

dpkg -P <package> Purges an installed package named <package>. The difference between remove and purge is that while remove only deletes data and executables, purge also deletes all configuration files in addition.

dpkg -L <package> Gives a listing of all the files installed by <package>. See also dpkg -c for checking the contents of a .deb file.

dpkg -s <package> Shows information on the installed package <package>. See also apt-cache show for viewing package information in the Debian archive and dpkg -I for viewing package information extracted from a .deb file.

dpkg-reconfigure <package> Reconfigures an installed package, if it uses debconf (debconf provides that consistent configuration interface for package installation). You can reconfigure debconf itself if you want to change the front-end or priority of questions asked. For example, to reconfigure debconf with the dialog front-end, you simply run:

dpkg-reconfigure --frontend=dialog debconf



echo ``<package> hold'' | dpkg --set-selections Put <package> on hold (command line method)

dpkg --get-selections ``<package>'' Get the current status of <package> (command line method)

dpkg -S <file> Searches for <file> in package database, telling you which packages have that file in them.

Building Debian packages from Source

apt-get source [-b] <package> Download the source Debian package for <package> and extract it. You must have deb-src lines in your /etc/apt/sources.list for this to work. If you supply the `-b' option and you are currently root, then the package will be automatically built if possible.

apt-get build-dep <package> Download and install the packages necessary to build the source Debian package <package>. This feature is only present in apt version 0.5 and up. Currently this means that woody and above contain this functionality. If you have an older version of apt then the easiest way to find out the build dependencies is to look in the debian/control file in the source package directory. A common usage of this command is in conjunction with apt-get source -b. For example (as root):

apt-get build-dep <package>
apt-get source -b <package>

Will download the source package, all of its build dependencies, and attempt to compile the source package.

dpkg-source -x <package.dsc> If you have downloaded the source package for a program manually, which includes several files such as a .orig.tar.gz (or .tar.gz if it is Debian native), a .dsc, and a .diff.gz (if it is not Debian native), then you can unpack the source package using this command on the .dsc file.

dpkg-buildpackage Builds a Debian package from a Debian source tree. You must be in the main directory of the source tree for this to work. Sample usage:

dpkg-buildpackage -rfakeroot -uc -b

Where `-rfakeroot' instructs it to use the fakeroot program to simulate root privileges (for ownership purposes), `-uc' stands for ``Don't cryptographically sign the changelog'', and `-b' stands for ``Build the binary package only''

debuild A handy wrapper script around dpkg-buildpackage that will automatically take care of using fakeroot or not, as well as running lintian and gpg for you.

Fixing dependencies

dpkg --configure --pending If dpkg quits with an error while apt-get install, upgrade, or dist-upgradeing try running this to configure the packages that were already unpacked. Then try apt-get install, upgrade, or dist-upgrade -f, and then try apt-get install, upgrade, or dist-upgrade again. Repeat as needed. This usually resolves most dependency problems (also, if it mentions a specific package for some reason, you might want to try installing or removing that package)

apt-get install -f
apt-get upgrade -f
apt-get dist-upgrade -f
 Attempt to fix dependencies while doing one of the above. Note that apt-get install -f does not require a <package> argument.


Taken from: http://www.cyberciti.biz/ref/apt-dpkg-ref.html

Monday, March 19, 2012

Ubuntu EOL (End-Of-Life)


If you only need access to some old repositories the only step you need to apply is adding/editing few lines in /etc/apt/sources.list.

## EOL upgrade sources.list
# Required
deb http://old-releases.ubuntu.com/ubuntu/ CODENAME main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ CODENAME-updates main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ CODENAME-security main restricted universe multiverse

# Optional
#deb http://old-releases.ubuntu.com/ubuntu/ CODENAME-backports main restricted universe multivers

Now just execute apt-get update and you can use those repositories.

Ubuntu versions


VersionCode nameRelease dateSupported until
DesktopsServers
4.10Warty Warthog20 October 200430 April 2006
5.04Hoary Hedgehog8 April 200531 October 2006
5.10Breezy Badger13 October 200513 April 2007
6.06 LTSDapper Drake1 June 200614 July 20091 June 2011
6.10Edgy Eft26 October 200625 April 2008
7.04Feisty Fawn19 April 200719 October 2008
7.10Gutsy Gibbon18 October 200718 April 2009
8.04 LTSHardy Heron24 April 200812 May 2011April 2013
8.10Intrepid Ibex30 October 200830 April 2010
9.04Jaunty Jackalope23 April 200923 October 2010
9.10Karmic Koala29 October 200930 April 2011
10.04 LTSLucid Lynx29 April 2010April 2013April 2015
10.10Maverick Meerkat10 October 201010 April 2012
11.04Natty Narwhal28 April 2011October 2012
11.10Oneiric Ocelot13 October 2011April 2013
12.04 LTSPrecise Pangolin26 April 2012[135]April 2017[129]