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]

Thursday, March 15, 2012

How to check if a processor is capable of 64-bit.

If you are running Linux, open the terminal prompt and run:
grep --color=always -iw lm /proc/cpuinfo
If this command returns lm (Long Mode) as one of the flags, then your processor is capable of 64-bit.
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc pni monitor cx16 lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt

Thursday, March 1, 2012

Wireshark match operator

matches   Does the protocol or text string match the given Perl regular expression?

fix.MsgType == "D" and fix.SecurityDesc matches "CLT|NGT"


The "matches" operator allows a filter to apply to a specified Perl-compatible regular expression (PCRE). The "matches" operator is only implemented for protocols and for protocol fields with a text string representation.

More information on PCRE can be found in the pcrepattern(3) man page (Perl Regular Expressions are explained in http://perldoc.perl.org/perlre.html).