Thursday, September 25, 2008

How do I find the name of the current shell that I am working in

There is a command that will work on all platforms I tested (HP-UX, SunOS, Linux, MacOS) and shells (sh,ksh,bash,csh,zsh)

ps -p $$ | grep $$ | awk '{ print $NF }'

Be aware that the shell name can be bash or -bash

Tuesday, June 24, 2008

At least one secondary cursor must be specified to DB->join error 22

Never found this problem on the Internet? Does it mean nobody except me run into it?

I have tested BerkeleyDB BTree 4.7.25 (from Oracle now) and when running a simple test described in their doc I got the following when opening (creating) a database:

At least one secondary cursor must be specified to DB->join error 22

After hours of searching here is what I found - the standard installation that comes the btree with is precompiled with a different Visual Studio that has a problem with VS 6.0 I was using. Even though I was able to download the dll (the release mode because the debug mode was wrong - shipped with improper MS nondebug libraries) the opening was returning this wrong message.

Only after opening the .dsw that came with the sources, and rebuilding it with VS 6.0 all went okay.

I hope it will help someone...

Friday, June 6, 2008

New download of the cvs repository on Windows

I have moved to a new laptop, and I had to get all the data from the cvs repository to this new one.
I wasn't even expecting so many problems with the WinCVS application to have!
No, it's not that WinCVS is bad. It's great. The point is that It gives so many options to accomodate so many users behaviours that at someome moment these options became a burden!

So I have finally decided to describe, step-by-step all the operations one needs to do in order to download new repository to his/her place.
This list is for cvs windows only.
I may to do this for Linux/Unix as well some time.
If you want to install WinCVS then, please, search on the Internet, wait for my new blog, or write to me in the comments.

RUN: <<<WinCVS>>>

MENU: <<<Admin/Login...>>>
EDIT: <<<CVSROOT:>>> - avoid using <<<...>>> It's overly confusing. It is better to enter the path:
EXAMPLE: :pserver;username=john;

BUTTON: <<<OK>>>
The CVS will ask you for the password which will be stored at your machine
in an encrypted form and will be used for communication every time you
access the repository, but until you click MENU: <<<Admin/Logout>>>
MENU: <<<Remote/Checkout module...>>>
DIALOG: <<<Checkout settings>>>
EDIT: <<<Module name and path on the server:>>>
EDIT: <<<Local folder to checkout to:>>>
CHANGE IT so it points at the ROOT directory where the ProjectAlpha directory will be created.
EXAMPLE: c:\JohnsProject\ (yes, add the backslash at the end!)

NOTE: If you DO NOT WANT to create the ProjectAlpha\ directory in the c:\JohnsProject one then you need to do:
CHECKBOX: <<<Check out into directory:>>> Turn in ON
EDIT: <<<Check out into directory:>>>
Drop down menu and select the last one that you have enteted a few steps above.
BUTTON: <<<OK>>>
Off you go!

After this operation, you will have your selected directory (c:\JohnsProject\ProjectAlpha, or c:\JohnsProject only) populated with the data.
from the server.

Thursday, June 5, 2008

Sending an email from PHP (on Windows too.)

Yey, finally got something that really works.
It's not my stuff, but I was able to found it after a long time search!
Here is the link to, to the page that hosts php Mailer for PHP 5 for Windows, and looks like for Unix too. If the link does not work then search for the word phpMailer.

The easiest way to install the stuff is to do as follows (example on Windows, with assumption that you have your php installed in the c:\php directory.)

> mkdir c:\php\mailer
Unzip into c:\php\mailer
> notepad.exe c:\php\php.ini
Add at the very end:

Youre done!

Now, example:
require_once( "class.phpmailer.php" ) ;

$mail = new PHPMailer() ;
$mail->IsSMTP() ;
$mail->Host = "" ;
$mail->SMTPAuth = true ;
$mail->Username = "username" ;
$mail->Password = "password" ;
$mail->From = "" ;
$mail->FromName = "It is me!" ;
$mail->AddAddress( "", "Poor Receiver" ) ;
$mail->AddReplyTo( "", "do-not-reply" ) ;
$mail->AddAttachment( "c:\\mydog.jpg", "Isn't she cute?" ) ;
$mail->Subject = "Sorry for this test email!" ;
$mail->IsHTML( true ) ;
$mail->Body = file_get_contents( "c:\\myemail.html" ) ;
$mail->AltBody = "non-HTML mail client? Where are you from?" ;

if( !$mail->Send())
printf( "Sending Error: " . $mail->ErrorInfo . "\n" ) ;
printf( "Message has been sent successfully.\n" ) ;

Friday, May 30, 2008

Script Shell Syntax checking

I'm writing a lot of stuff in shell (Korn,Bourne,Bash) and I had a need for syntax checker in the build time. Something I could use either in the command line (like a compiler) or in the make time which should stop the build whenever there is a syntax error in my script.

Here is what I came up to. Simply copy/paste the code below to a file named (or whatever you wish to call it), do chmod+x and off you go!

cat |

You can also use it in the makefile. It will return value 1 if there was an error.
shck_return() {
    return $1
echo "set -n ">random.$$.sh
cat $1 >>random.$$.sh
chmod +x random.$$.sh
./random.$$.sh >errors.$$.err 2>errors.$$.err
rm -f random.$$.sh
grep -v ": warning: line" errors.$$.err | sed -e s/random.$$.sh/$1/g >errors.$$.err2
[ -s errors.$$.err2 ] && {
    cat errors.$$.err2
rm -f errors.$$.err errors.$$.err2
shck_return $shck_errno

Wednesday, May 28, 2008

Opening unopenable attachments in Microsoft Outlook

The Microsoft Outlook software, starting, as I believe, from version 2003, turned opening some of the attachments for good. If you received, for example, an .mdb file (from Microsoft Access,) then you will only see that you got it, but you won't be able to copy it to the hard drive. Don't try searching in the options as suggested in the email. There is no option to turn the ability to detach the attachment on.
Microsoft says it clearly - because it is one of the most popular applications for managing emails, it has been constantly under attach by the hackers, so to 'save' their customers, they turned several options off for good. There is a workaround though. You can ask the sender to send you the file again, but ask him/her to rename the extension of the file or to zip/rar it. If such option is not a good one, or at least not for the very moment because you're in a hurry, there the following solution:

Run regedit: WARNING, WARNING: These operations are dangerous, so if you're not feeling secure, don't play with regedit. Screwing up in this file may screw up with your Windows installation and ultimatelly you may have to reinstall your OS!!!!

Open HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Security
(11.0 is for Outlook 2003)

Create or add a New String Value under this key with the name: Level1Remove

Enter the file extensions separated with the semicolon (;) that you would like to support in the attachment. The file extensions should start with a coma.

Level1Remove .mdb;.xlsx

Typical errors:
- forgetting to put a dot in the front of the extension
- putting spaces into the Level1Remove value
- Putting Level1Remove string into improper place in registry
- Creating a KEY instead of a STRING VALUE in registry.

When you are done, close the regedit program, close your Microsoft Outlook application, and open it again. From that moment, the files with the extensions you have just added into registry will be available for you.

Make sure you don't overdo and don't add others files 'just in case'. You may put yourself in danger by allowing to accept .exe, .bat, .js and other executable files. Use your head!

jpg - changing internal date and time stamp

Ooops. I have set an improper date on my digital camera and now, Picassa shows my pictures in improper order. I take care of setting the date and time stamp of the file but even though, Picassa puts my new pictures amont the last year ones.

I started searching for a tool that would allow me to change the internal jpeg (jpg) date and time stamps, and I have run onto a very nice one - file Tweak ( The sad part this tool, being really an excellent Windows addition to the file properties dialog box, cost money, and I didn't want to spend money to, from time to time, fixing my mistakes. (You can download a limited in time and functionality filetweak from them.)

I have decided to take a closer look to the jpg file and check if I can change the date and time opening the file in binary mode (I use Visual Studio, but you can find other free tools that can do it for you.)

What a surprize - the date time is stored in DOS open format!
Example: 2008:05:25 22:36:40

In my jpeg files are three dates (when the picture has been taken, when was digitalized and when was modified.)

The easiest way then, to change the timestamp of your jpeg files is:

Search for the year your picture has been taken (Right-click on the file, Properties,Summary tab,Make sure Advanced button is on, Search for Date Picture Taken.)
Simply, using any binary editor, modify the date and/or time of the jpg files (up to three places to be changed) and save the file. You're done. Picassa and you will be happy :)

Saturday, May 24, 2008

Running a command for each value comming back from an ODBC query in PHP

I have a need to read an ODBC datasource and run a query on a particual table. For each unique value of the table, I need to run a command in the shell.

Here is anexample:

$values = Array() ;
$command = "echo" ; /* for the example purposes the command is echo */
$columnName = "state" ; /* just for this example */

$hdbc = odbc_connect ( "dsn-name", NULL, NULL ) ;
if ( $hdbc != NULL )
$hstmt = odbc_prepare(
, "select distinct " . $columnName . " from tablename"
) ;
if ( $hstmt != NULL )
if ( odbc_execute( $hstmt ))
while ( odbc_fetch_row( $hstmt ))
$values[] = odbc_result( $hstmt, 1 ) ;
printf( "*** Unable to execute\n" ) ;
printf( "*** Unable to prepare the query.\n" ) ;

odbc_close( $hdbc ) ;
printf( "*** Unable to connect\n" ) ;

foreach ( $values as $value )
system( $command . " \"" . $value . "\"" ) ;

Friday, May 23, 2008

Publishing an Excel table as static html using jscript.

Oh man! I have worked on it a few days, posted numerous questions on various newsgroups, spent hours on the Internet and in a book store, and finaly I got what I needed!

I have a sheet (Sheet1) in my xlsx document (Excel 2007) which I wanted to save as a static html page using.
I want to use jscript run in the command line, so I could automate the process.
I don't want to use SaveAs( ..., 44 ) method because it creates the sheet name at the bottom.
I also don't want to have the ActiveX embedded into the page (no dynamic html.)

Assuming that the document is c:\mydoc\test.xlsx, I want to generate c:\mydoc\test.html file.

Here is the code of doit.js file:

ea = new ActiveXObject( "Excel.Application" ) ;
ea.DisplayAlerts = 0 ; /* Don't want to see any questions on the screen! */
wb = ea.Workbooks.Open( "c:\\mydoc\\test.xlsx" ) ;
po = wb.PublishObjects ;
po.Add( 1, "c:\\mydoc\\test.html", "Sheet1" ) ; /* 1 == static html. */
po.Item( 1 ).Publish( true ) ; /* Yahoo! */
wb.Close( false ) ; /* I don't want to save the newly added PublishObject */

Isn't that cool!

Tuesday, May 13, 2008

Setting up registry to run .php scripts from command line

I wanted to have a script in php that I could run in the following way:

c:\tmp> myscript.php argument1 "second argument"

This is what I came up to:

a) In the file explorer (not internet! file!) double click on your .php script, select the 'Select the program from a list', Browse to php.exe, mark 'always use the selected program to open this kind of file', and accept.

This, will create a HKEY_CLASS_ROOT/.php entry with the value php_auto_file.
It will also create the HKEY_CLASS_ROOT/php_auto_file/shell/open/command with the default entry: "c:\php\php.exe" "%1"
(the path to the php.exe file depends on where you have installed php in!)

This kind of registration will allow you now running your scripts from the command line but it WON'T allow you to pass any arguments.

b) That's why you have to the HKEY_CLASS_ROOT/php_auto_file/shell/open/command entry to the following: "c:\php\php.exe" "%1" %*

Here you go. Now you can prepare your myscript.php to look like this, and test the execution:
print_r( $argv ) ;

myscript.php argument1 "second argument"


[0] => c:\tmp\myscript.php
[1] => argument1
[2] => second argument

Friday, May 2, 2008

poll: protocol failure in circuit setup (Linux)

To tell the truth, I'm not sure it's the Linux issue only. It can be on other platforms as well.

If you saw something like this in telnet/ssh:

connect to address port 544: Connection refused
Trying krb4 rsh...
connect to address port 544: Connection refused
trying normal rsh (/usr/bin/rsh)
poll: protocol failure in circuit setup

then what probably causes it is firewall (iptables)
The quicky method is simply to shutdown the iptables firewall:
> su -
> services iptables stop

However, if you reboot your machine, the iptables will start and you will hit the problem again.

To permanently shut down the firwall service then, do the following:
> su -
> chkconfig --list iptables

- you will probably see this:
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off

- then do:
> chkconfig --level 345 iptables off
> chkconfig --list iptables

- now you should see this:
iptables 0:off 1:off 2:on 3:off 4:off 5:off 6:off

Of course, for the current session, you still will have to call service iptables stop, but I guess you already know it.

Wednesday, April 9, 2008

Returning error code from a script in Linux

Most people moving to Linux are getting surprised by the fact that a simple operation "return 1" can cause an error:

./ line 1: return: can only `return' from a function or sourced script

Not all Linuxes return this problem, however, it's enough anoying if you want to keep the script for all the platforms.

There is a simple solution for this, though!

# $1 - error code
fun_return() {
return $1

fun_return 1

You can check this out by yourself. Write a sctipt with the above example, run it and check the value of $?

UNIX/Linux shell and returning values from functions

Here is an interesting fact.

Let's assume you want to write a function myfun_initialize()

If the function is supposed to initialize some variables then DO NOT RETURN result of this function through the `function caller` (well, I have just made up this name.)

In other words...

myfun_initialize parameters
[ "$var_initialize" = "ok" ] {
echo "Oops!"

[ "`myfun_initialize parameters`" = "ok" ] {
echo "Oops!"

Why is it wrong? I wish I had a simple explanation, but if the myfun_initialize function initializes some external variables you would like to use later on, then by calling `myfun_initialize` you will initialize temporary variables, and these outside of the call will be unchanged!

Test it yourself:

Here is the text


# $1 - value
myfun() {

echo "MYVAR before calling myfun is $MYVAR"
if [ "`myfun something`" = "" ]
echo "myfun returned an empty string"
echo "MYVAR after calling \`myfun something \` is $MYVAR"
echo "myfun hasn't returned an empty string?!"
echo "MYVAR after calling \`myfun something\` is $MYVAR"

myfun something
echo "MYVAR after calling myfun something is $MYVAR"

So what is the solution?
Use a variable to return the result.

myfunc() {

[ "$myfunc" = "ok" ] && {

HP-UX - group permissions issue

Let's assume that there is a guy user name paul who's main group is developer.
His home directory belongs to paul:developer.

Now, let's assume my main group is users, and the developer group is my secondary one.

You would expect, probably, that I could do cd ~paul if only paul's home directory had g+rx attribute, right?

Well, on HP-UX (at least) it does not have to be like that. I don't know if this is by default or not but what I have found out on our HP-UX machine is that there are two files in the /etc dirtectory - group, and logingroups.

For sure you know the /etc/group file!
I bet you might not see the /etc/logingroups file, though.

Now, if you want to make HP-UX behaving like other machines, you can simply create a link:

ln -s /etc/logingroups /etc/group

After this change my user will be able to do cd ~paul.

Let's begin

The first but hopefuly not last post will, in my deep hope, open a new era for my knowledge storage.
So far, blogging wasn't my thing.
But hey, I have just realized that I can store my knowledge in here and have an access to it from various places.
If you, my dear reader, hope for big time secrets then you're up to big time disapointment.
Yes. The stuff I'm about to put in here is not about how to conquer the world (if I only knew how to spell it!)
It's a simple stuff regarding various products and solutions/workarounds I'm finding. A little bit of coding.