| No comment yet

Connect MSSQL using ODBC in Linux (CentOS)


For connecting MSSQL using ODBC in Linux you can use unixODBC and freeTDS.  unixODBC is a tool for using ODBC in Non Windows platform. MSSQL uses Tabular Data Stream (TDS) as a communication protocol which is same like in Sybase. freeTDS is an implementation of TDS protocol.

Installing unixODBC
      1.      Install gcc
#yum install gcc

      2.      Download unixODBC and untar it
#mkdir /root/downloads
#cd /root/downloads
#wget ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.0.tar.gz
#tar –xzf unixODBC-2.3.0.tar.gz
#cd unixODBC-2.3.0

      3.      Install unixODBC
#./configure
#make
#make install

Installing freeTDS
     1.      Set environmental variable at /etc/profile. Add following lines at end
#nano /etc/profile


# TDS
SYBASE=/usr/local
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$SYBASE/lib
export SYBASE LD_LIBRARY_PATH
/etc/profile

     2.      Download freeTDS and untar it
#cd /root/downloads
#wget ftp://ftp.astron.com/pub/freetds/stable/freetds-stable.tgz
#tar –xzf freetds-0.82.tar.gz
#cd freetds-0.82
     3.      Install freeTDS
# ./configure --with-tdsver=8.0 --with-unixodbc=/usr/local
#make
#make install

     4.      Now all your library will be inside /usr/local/lib and configuration files inside /usr/local/etc

     5.      Make template to register ODBC driver with unixODBC
#nano /usr/local/etc/tds.driver.template


[FreeTDS]
Description     = v0.63 with protocol v8.0
Driver          = /usr/local/lib/libtdsodbc.so
tds.driver.template
     6.      Now install the driver entry using above template
# odbcinst -i -d -f /usr/local/etc/tds.driver.template

     7.      Make template to create ODBC data source name
#nano /usr/local/etc/tds.datasource.template


[MSSQLTest]
Driver  = FreeTDS
Description     = Sample Database
Trace   = No
Server      = 192.168.0.1
Port      = 1433
Database        = TestDB
tds.datasource.template
     8.      Now create odbc data source using above template
# odbcinst -i -s -f /usr/local/etc/tds.datasource.template

     9.      Finish. You can test it by giving command
                       # isql -v MSSQLTest username password
| No comment yet

Perl one-liners


Collection of one-liners, a part is adapted from such a list by
Tom Christianson, one of the authors of "Programming Perl".

    # the always present hallo world program, adapted to a Math department
    perl -e 'print "Hello Mr Euler!\n"'

    # rename in each file name the string aaa by bbb
    ls | perl -ne 'chomp; next unless -e; $o = $_; s/aaa/bbb/; next if -e; rename $o, $_';

    # add first and last column in each line of file foo.txt and print it out
    perl -lane 'print $F[0] + $F[-1]' foo.txt

    # print lines 15 to 17 of file foo.txt
    perl -ne 'print if 15 .. 17' foo.txt

    # a second way to print lines 3 to 5 of file foo.txt
    perl -pe 'exit if 3<$. && $.<5' foo.txt

    # change all words "foo"s to "bar"s in every .c file and keep backups
    perl -p -i.bak -e 's/\bfoo\b/bar/g' *.c

    # the same but without backup. Remember the flags: "eat the pie"
    perl -p -i -e 's/foo/bar/g' *.c

    # changes ^M newline characters to newlines
    perl  -p -i -e 's/\012?\015/\n/g'  $1

    # the same but with all files with name filename
    perl -p -i -e  's/foo/bar' `find . -name "filename"`

    # substitution can also be applied to binary files like test.ppm
    perl -p -i -e 's/255/127/g' test.ppm

    # substitute "xyz.math" to "abc.math" in every .html file and keep backups
    perl -p -i.bak -e 's/xyz\.math/abc\.math/g' *.html

    # insert department name after each title and keep backup
    perl -p -i.bak -e 's#<title>#<title>Harvard .: #i' *.html

    # delete first 10 lines in foo.txt and keep backup foo.txt.bak
    perl -i.bak -ne 'print unless 1 .. 10' foo.txt

    # change isolated occurrence of aaa to bbb in each file *.c or *.h
    perl -p -i.bak -e 's{\baaa\b}{bbb}g' *.[ch]

    # reverses lines of file foo.txt and print it
    perl -e 'print reverse <>' foo.txt

    # find palindromes in a dictionary /usr/share/dict/words
    perl -lne 'print if $_ eq reverse' /usr/share/dict/words

    # reverses paragraphs in file foo.txt
    perl -00 -e 'print reverse <>' foo.txt

    # increments all numbers in foo.tx by 1
    perl -pe 's/(\d+)/ 1 + $1 /ge' foo.txt

    # reverses order of characters in each line of foo.txt
    perl -nle 'print scalar reverse $_' foo.txt

    # print lines beween START and END in foo.txt to STDOUT
    perl -ne 'print if /^START$/ .. /^END$/' foo.txt

    # delete lines beween START and END and backup original file
    perl -i.old -ne 'print unless /^START$/ .. /^END$/' foo.txt

    # look for duplicated words in a line
    perl -0777 -ne 'print "$.: doubled $_\n" while /\b(\w+)\b\s+\b\1\b/gi' foo.txt

    # start Perl debugger "stand-alone"
    perl -d -e 42

    # run a Perl program program.pl with warnings
    perl -w program.pl

    # run a Perl program program.pl with debugger
    perl -d program.pl

    # Run perl program program.pl, check syntax, print warnings
    perl -wc program.pl

| No comment yet

Delete Qmail Server messages Queue


qmail is a mail transfer agent that runs on Unix. It was more secure replacement for the popular Sendmail program. The author offered a $500 prize for the first person to publish a verifiable security hole in the latest version of the software.

This is a useful thing to do in a number of situations. For instance, if you are hit with a spamming attack, you can temporarily instate a second Qmail installation (once the spam run is finished), allow it to take over mail receipt,and then use this tool to clean the offending mails out of the queue before switching over to the main Qmail installation once again.

Occasionally, viruses will get past scanners before the signatures get updated; if they exist in large numbers, it is often practical to stop the Qmail install briefly in order to clean out all messages containing a signature related to the virus.

Whatever the reason to pull items from your mail queue, this program will delete them in such a manner that will let you restore them easily.

Here we are going to see different Technics how to delete or remove your qmail server queue

====================================================================

1)You can edit the /var/qmail/control/queuelifetime file this is the file to control how long a message stays in a queue.Just put a number (to represent seconds)in this file.By default 86400 sec Will keep the mail for 1 day and expire after that.Here you can change this value to 1 and restart your qmail server it should clear your qmail queue.

2)Deleting mails from qmail queue

Following commands can delete all mails from your qmail mail server queue.

qmailctl stop
find /var/qmail/queue/mess -type f -exec rm {} \;
find /var/qmail/queue/info -type f -exec rm {} \;
find /var/qmail/queue/local -type f -exec rm {} \;
find /var/qmail/queue/intd -type f -exec rm {} \;
find /var/qmail/queue/todo -type f -exec rm {} \;
find /var/qmail/queue/remote -type f -exec rm {} \;