Saturday, 9 June 2012

how to test PHP 5 compilation with sybase 15

While back I had to recompile PHP 5.x with Sybase 15 support. It wasn't difficult, but after compilation was finished, I had to test it somehow... and here's a small and basic piece of PHP code to test connection from PHP 5 to ASE 15 (Adaptive Server Enterprise).

----------

<?php
$db = sybase_connect("SERVER", "username", "password") or die("Could not connect !");
echo "Connected successfully<br>";
echo "handler: $db<br>";
$res = sybase_query("select column from table", $db);
 if($res)
 {
         echo "rows: sybase_num_rows($res)";
         while ($data = sybase_fetch_array($res)) {
          print("db: $data[0]\n");
         }
 sybase_free_result($res);
 } else  {
         echo "<br><br>false<br><br>";
         }
 echo "<br><br>last message from server:<br>";
 echo sybase_get_last_message();
 sybase_close($db);
?>

how to debug linux bash script

bash - GNU Bourne-Again SHell. Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file.  Bash also incorporates useful features from the Korn and C shells (ksh and csh).

-x parameter puts bash into debug mode, so if you would like to execute your bash script in debug mode, you can do it this way:

# bash -x yourscriptname.sh

another solution is to add "set -x" line into your script, but you have to remember that this will make your script produce debug output every time it's executed. If you prefer this way, just add "set -x" line at the begining of script:

#!/bin/bash
set -x
...

The #1 programmer excuse for legitimately slacking off




The #1 programmer excuse for legitimately slacking off: "My code's compiling."

Friday, 8 June 2012

linux CentOS 6.2 denyhosts installation

Linux Cenos 6.2, base system installed from: CentOS-6.0-x86_64-minimal.iso
# uname -a
Linux xxx 2.6.32-71.el6.x86_64
# yum install denyhosts
Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
 * base: mirror01.th.ifl.net
 * extras: mirror01.th.ifl.net
 * updates: mirror01.th.ifl.net
Setting up Install Process
No package denyhosts available.Error: Nothing to do
denyhosts package is not included in Centos repositories, but it's pretty easy to download sources and build it. Sourceforget denyhosts project website: http://sourceforge.net/projects/denyhosts/
# wget http://downloads.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fdenyhosts%2Ffiles%2Fdenyhosts%2F2.6%2F&ts=1320260346&use_mirror=sunet
]# -bash: wget: command not found

ehm... "yum install wget" solved the problem, software downloaded, ungzip, untar.

# python setup.py install
# cd /usr/share/denyhosts
# cp daemon-control-dist /etc/init.d/denyhosts
# cp denyhosts.cfg-dist denyhosts.cfg

I have no idea why, but config specify this location as WORK_DIR, but this directory is not created by setup script by default, so...

# mkdir /usr/share/denyhosts/data

this is where you can create file "allowed-hosts" to white-list your trusted IPs, from denyhosts documentation: "Since it is quite possible for a user to mistype their password repeatedly it may be desirable to have DenyHosts prevent specific IP addresses from being added to /etc/hosts.deny. To address this issue, create a file named allowed-hosts in the WORK_DIR. Simply add an IP address, one per line. Any IP address that appears in this file will not be blocked."

# chkconfig --level 3 denyhosts on

# chkconfig --list denyhosts
make sure it's activated for level 3 and... all done here...

Friday, 1 June 2012

Bash exit status code basics...


bash exit status code basics:

exit status 0
command executed successfully

non-zero exit status
command executed with errors

quick facts about bash exit codes:

variable $?
can be used to determine the exit status of the last executed command.

calling "exit" in bash script without parameter will return the exit code of the last executed command, so "exit" and "exit $?" should return exactly same bash exit code.