Saturday, January 15, 2011

How to count all subfolders in an directory?

How can I count how many folders (including subfolders) I have under an specific folder?

  • Use find to select the directories and wc to count them.

    find <directory> -mindepth 1 -type d | wc -l
    
    : Wow, is there an faster solution? ;-) ------------------------------------------------- time find product_images/ -mindepth 1 -type d | wc -l 574292 real 67m34.672s user 0m4.272s sys 0m35.790s -------------------------------------------------
    Dan Carley : That's a big tree. The only way you can speed it up is to work on an index of that structure. But creating and updating the index will be just as slow. And the most common tool for indexing and searching the local FS, `locatedb`, won't allow you to refine your search in the same way as `find`.
    asdmin : yes, with 574292 subdirs and who knows what many files, it's the fastest way to cound the dirs
    From Dan Carley
  • tree -d | grep directories | awk -F' ' '{print $1}'

    Dennis Williamson : I'd use `tail` since there could be a directory called "directories" and there's no need for the -F with the awk: `tree -d|tail -n1|awk '{print $1}'`
    From dyasny

How to update SSL certificate with Tomcat 5.5

My client is running Tomcat 5.5 and is using SSL. Their certificate is about to expire and they have purchased a renewal. I was given a .cer file and asked to update Tomcat.

The existing server.xml contained the following connector:

<Connector port="443" maxHttpHeaderSize="8192"
           maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
           enableLookups="false" disableUploadTimeout="true"
           acceptCount="100" scheme="https" secure="true"
           clientAuth="false" sslProtocol="TLS"
           keystoreFile="companyname.keystore" keyAlias="tomcat2" />

I ran %JAVA_HOME%\bin\keytool -list -keystore companyname.keystore

Keystore type: jks
Keystore provider: SUN

Your keystore contains 3 entries

root, Aug 7, 2007, trustedCertEntry,
Certificate fingerprint (MD5): 8F:5D:77:06:27:C4:98:3C:5B:93:78:E7:D7:7D:9B:CC
tomcat, Jun 12, 2007, keyEntry,
Certificate fingerprint (MD5): 33:80:6F:75:5A:B4:BC:C7:7A:7D:4F:3F:FA:C0:95:2F
tomcat2, Jun 14, 2008, keyEntry,
Certificate fingerprint (MD5): 0A:9B:73:6A:EE:2F:18:99:61:49:28:F3:CD:1E:DF:96

SSL still works if I delete the entry with the alias "tomcat". I'm assuming that's an artifact from a previous expired certificate.

%JAVA_HOME%\bin\keytool -import -keystore companyname.keystore -alias tomcat3 -file 2009cert.cer

I updated server.xml to set keyAlias to tomcat3. When I restart Tomcat, I see this in the log:

SEVERE: Error initializing endpoint
java.io.IOException: Alias name tomcat3 does not identify a key entry
    at org.apache.tomcat.util.net.jsse.JSSE14SocketFactory.getKeyManagers(JSSE14SocketFactory.java:143)
    (etc.)

When I re-run the keytool -list command:

Keystore type: jks
Keystore provider: SUN

Your keystore contains 4 entries

root, Aug 7, 2007, trustedCertEntry,
Certificate fingerprint (MD5): 8F:5D:77:06:27:C4:98:3C:5B:93:78:E7:D7:7D:9B:CC
tomcat, Jun 12, 2007, keyEntry,
Certificate fingerprint (MD5): 33:80:6F:75:5A:B4:BC:C7:7A:7D:4F:3F:FA:C0:95:2F
tomcat3, Jul 21, 2009, trustedCertEntry,
Certificate fingerprint (MD5): 8E:9F:F9:52:7B:07:B1:DB:BF:F3:96:BD:5F:49:2E:9F
tomcat2, Jun 14, 2008, keyEntry,
Certificate fingerprint (MD5): 0A:9B:73:6A:EE:2F:18:99:61:49:28:F3:CD:1E:DF:96

Does this have something to do with the tomcat3 entry being marked as "trustedCertEntry" rather than "keyEntry"?

What am I doing wrong?

  • The fact that it's registering as a TrustedCert would seem to indicate that there's no key for tomcat3. It's likely that the new certificate was requested for the existing key tomcat2. Keys themselves don't expire, just the certificates.

    You can request a new certificate at any time either by generating a new cert signing request or by reusing the original one either of which is fine. Take a backup copy of your keystore and then import the certificate for the tomcat2 alias.

    %JAVA_HOME%\bin\keytool -import -keystore companyname.keystore -alias tomcat2 -file 2009cert.cer
    

    After that, you'll also want to point your tomcat instance back at tomcat2.

    Jeremy Stein : When I try that, I get this error: keytool error: java.lang.Exception: Public keys in reply and keystore don't match
    Frenchie : By the look of it, the only other key in the keystore is tomcat, so give that a try instead of tomcat2. Failing that, someone has gotten a csr from another key elsewhere. Importing keys into a keystore is possible but it's non trivial.
    Jeremy Stein : You nailed it. It turns out the client had created a new private key and CSR and hadn't mentioned that fact. Thanks!
    From Frenchie

Open Source alternative to "Google Appliance" for intranet search?

Are there any alternative open source solutions (with a web console)?

  • Try this: http://www.flax.co.uk/index.shtml

    (I have no experience with this product or other enterprise search products).

  • I have used 'htdig' in past for intranet search. It is good and indexes pdf documents by default. Once you can add filters that can translate documents to text format for indexing, it will start supporting other formats as well.

  • Its not open source, but Microsoft Search 4.0 is free at this link

    I would say its worth trying, I liked the formatting of the results returned, but the problem was the results would include documents a user could not access due to security. So it was no good for us since document names can contain restricted information too, such as "Bob-Warning Letter.doc"

  • I've found a solution with Google Desktop Search (Which can be used like a web appliance with a plugin): read more...

    SpaceManSpiff : Sounds like the same thing Microsoft Search Server will do, but with more effort.
    Martin K. : More effort but free of charge!
    SpaceManSpiff : Microsoft's Search Server Express is completely free of charge and the only difference between it and the Enterprise edition is that Express does not have load balancing. By the way need for DNKA plug in according to your link has a small charge for commercial use. Funny how google requires you to use their hardware for their enterprise searches. I think google could clean up in this area if they released a server edition software that could be installed on your own server.
    Martin K. : The information from the page is outdated! DNKA is now free for commercial use. The solution is absolutly free of charge. When I try to download the express edition, everywhere "Demo" or "Test" is shown!? Why should google require to use their hardware? The solution I mentioned is free of charge and requires only an windows environment. It works also with Mozilla as client (eg. from Unix/Linux boxes). I've read that the google search performance is significantly better.
    SpaceManSpiff : Try this link - http://www.microsoft.com/enterprisesearch/en/us/search-server-thankyou.aspx You were likely trying download the full enterprise which is a trial edition. Cool that your DNKA is free now. So is this one. What I was trying to say is that a company to have an intranet search from google (without it being a mashup) requires a google appliance. It would be great if google did a software only enterprise intranet search, that was not a mashup of their desktop search & 3rd party tools. More admin's would prefer that I think.
    Martin K. : They have souch a product (Google Appliance) for sale. I don't think that they'll give it away for free. Google Desktop search doesn't rely to any specific hardware (excepting x86, but that's your windows solution too).
    From Martin K.
  • Solr, from the Apache Lucene project. Excerpt from the web site

    http://lucene.apache.org/solr/

    Solr is an open source enterprise search server based on the Lucene Java search library, with XML/HTTP and JSON APIs, hit highlighting, faceted search, caching, replication, a web administration interface and many more features. It runs in a Java servlet container such as Tomcat.

    From Will Glass

Strange GD error when working on PNG images from PHP on FreeBSD

I have a problem with my FreeBSD 7.1 server. PHP's GD implementation no longer works on PNG images. Whenever the system tries to work with PNG images, I get these three error messages:

[Sat Jul 18 21:41:15 2009] [error] [client 90.34.34.34] PHP Warning:  imagecreatefrompng() [function.imagecreatefrompng]: gd-png:  fatal libpng error: [00][00][00][00]: unknown critical chunk in /usr/storage/www/private/mikkel.hoegh.org/modules/acquia/imageapi/imageapi_gd.module on line 44, referer: http://mikkel.hoegh.org/admin/build/imagecache/3
[Sat Jul 18 21:41:15 2009] [error] [client 90.34.34.34] PHP Warning:  imagecreatefrompng() [function.imagecreatefrompng]: gd-png error: setjmp returns error condition in /usr/storage/www/private/mikkel.hoegh.org/modules/acquia/imageapi/imageapi_gd.module on line 44, referer: http://mikkel.hoegh.org/admin/build/imagecache/3
[Sat Jul 18 21:41:15 2009] [error] [client 90.34.34.34] PHP Warning:  imagecreatefrompng() [function.imagecreatefrompng]: 'sites/mikkel.hoegh.org/files/imagecache_sample.png' is not a valid PNG file in /usr/storage/www/private/mikkel.hoegh.org/modules/acquia/imageapi/imageapi_gd.module on line 44, referer: http://mikkel.hoegh.org/admin/build/imagecache/3

I've been trying to solve this half a day now, and the best clue I've found is another guy having the same problem – no solution there, though.

The code in question is fairly simple, it just calls imagecreatefrompng($filename);

Package versions of all the packages I can think of that might be related:

  • php5-5.2.10
  • php5-gd-5.2.10
  • png-1.2.37
  • gd-2.0.35_1,1

Any clues?

  • It could be problem with PNG image. Try very basic code with very small black and white PNG image. If that also generates same errors in log files then you could consider installing PHP from source so that modules like php_gd get updated to latest version.

    You can also try setting

    error_reporting  =  E_ALL
    display_errors = On
    

    in case they give some better error message on screen. Remember to make display_errors=Off after you have finished debugging on a production server.

    mikl : Well, it is the same with all PNG images I've tried. And as far as I can see, the error message is exactly the same whether you output it to the log or to the screen.
    Saurabh Barjatiya : Based on your distribution you would have some package manager like yum or apt. Try updating apache, php, php_gd using that package manager. If that does not works then I guess recompiling PHP from source would be the best option.
    mikl : The versions I mentioned are the latest available – I have tried the upgrade strategy already…
  • I had a recent problem similar to this. After upgrading one of the packages on my 7.2 system, the gd-driven captcha on my phpBB2 installation stopped working. I re-built all of the php ports and it fixed itself.

    I know that's a bit vauge, but sometimes things will break over months of incremental upgrades due to dependencies getting out of whack.

    mikl : Yeah, I already tried to rebuild php-gd with all of its dependencies. I think I might try something more… drastic. I have an upgrade to 7.2 I've been putting off for a while, so if I have to rebuild all my packages, that might be a good occation :)
  • No answer but since I cannot leave any comment; I have a 7.2 system with exactly the same problem and exactly the same versions. Even tried downgrading libpng to no avail. Doing a binary upgrade from 7.1. to 7.2 was extremely painless and well worth it but don't think that will fix the problem :-)

    I also installed pecl-imagick to see if I could use that instead but to my surprise I got similar errors. I tried lots of other software that depends on libpng but they could all load the images giving errors in php5-gd and pecl-imagick just fine. This made me exclude libpng, which at first I thought was the problem. My next guess is that something in the php API has changed, I will try to downgrade php and see if that helps.

    mikl : Okay, interesting – I've managed to get my image processing working by using imagemagic (the CLI util, not the pecl package). That could indicate that this might in fact be a PHP bug. *shakes tiny fist at PHP*
  • Before updating always read

    /usr/ports/UPDATING
    

    Sometimes you'll need to do recursive portupgrade i.e.

    portupgrade -fr png-1.2.37
    
    mikl : Was there anything in particular I should have noticed in UPDATING? I can't spot something related to this problem. I don't use portupgrade, but I'm running a `sudo portmaster -ru graphics/png` now to see if that'll fix it.
    mikl : Recursive rebuild did not fix the problem, sadly. I tried earlier by rebuilding all dependencies of php5-gd, but that had no effect either.
    SaveTheRbtz : maybe, as last resort, `portmaster -fa` will help?
    mikl : Thankfully, it has disappeared after I upgraded to FreeBSD 7.2. I think the decisive change was the complete rebuild of all packages. Thanks.
  • This command solve my problem:

    portupgrade -fr png-1.2.40

  • If you are using portmaster, this will work:

    portmaster -dbrR png-1.2.40
    
    From Markus

Which disk mode is most fast and reliable in vmware server 1.9 (ubuntu 64 bit guest)

I don't want snapshots and they are deactivated in the guest, which is ubuntu 64 bit.

Which disk mode is the most fast and reliable in vmware server 1.9? (I am using scsi)

I am not sure if it is "dependent" or "independent persistent". Actually I don't understand what dependent in this case means.

(I assume "independent persistent" is not the right choice because it is less safe)

So my priority is safe and fast and I don't want snapshots.

Edit: My question was not what I wanted. I want the fastest setting. If snapshots activated (while I never use them) is the fastest, then I want this. So which one is the fastest settign for virtual disks?

  • Independent and dependent refer to snapshots.

    Independent disks do not get snapshotted if a snapshot is taken while dependent disks do get snapshotted.

    If you aren't using snapshots, there's no difference in behavior practically speaking.

    Persistent and non-persistent refer to whether or not changes are written to the virtual disk permanently.

    If a disk is persistent, changes to the disk are written. If a disk is non-persistent, changes are lost when the VM is shutdown or restarted.

    I don't know that either has a specific impact on performance of the virtual disk.

    From damorg

Why exactly is --skip-slave-start recommended with MySQL `START SLAVE UNTIL`?

When issuing START SLAVE UNTIL on MySQL , I'm getting the following:

Warning: It is recommended to use --skip-slave-start when doing step-by-step replication with START SLAVE UNTIL; otherwise, you will get problems if you get an unexpected slave's mysqld restart.

Why exactly is it recommended to use --skip-slave-start? What happens if the slave indeed restarts - does it only forget the UNTIL part and replicates till the end of binlog?

  • Does it only forget the UNTIL part and replicates till the end of binlog?

    That's right.

    If a previously configured slave is started without --skip-slave-start, then it will use the information stored in master.info to automatically reconnect and continue replication like normal - that is without the UNTIL clause. Which means proceeding to the end of the binlog and waiting for new binlog events.

    Rafał Dowgird : Thanks, I hope there are no other hidden reasons :)
    From Dan Carley

Free tool for analysis of IIS logfiles?

Possible Duplicate:
Any freeware IIS log analyzer?

Hi there,

what are the best free tools available to analyze IIS logfiles?

Thanks in advance!