I've put up quite a few Perl scripts here over the years. A number of them are for accomplishing various tasks related to Kerio products. While I certainly strongly recommend that customers choose Linux or Mac over Windows, not everyone takes my advice, which means that the Kerio related Perl scripts aren't necessarily immediately useful to everyone.
You can certainly get Windows Perl ports (Strawberry Perl, for one), but these scripts sometimes are written with a strong Linux/Unix slant and there could be a fair amount of work involved to translate them properly.
It's much easier to use Cygwin. Getting Cygwin installed might be a little more difficult than typical Windows packages, but it's not all that hard and, once it's done, you'll be able to easily do things that are otherwise very difficult in Windows. Cygwin is free, so let's go install it now:
Download Setup from http://cygwin.com/install.html. I suggest moving it to your Desktop or at least somewhere where you can find it easily again because this program is also used for updates and configuration.
The installation (and in future updates) will ask you for a mirror site to use for downloading. Windows people don't expect that; just select one of the listed servers and continue along.
If you just choose the default install, you won't get Perl. Add it by searching for it and selecting these packages.
You are also going to want a text editor. I prefer "vim", but most people are put off by its learning curve. You can write your scripts in Windows, but you may need to translate line endings. For that, you'll also want to install the cygutils package and use the conv, d2u, dos2unix, u2d, and unix2dos programs from there. The "conv" is easy enough:
Usage: conv [OPTION...] [input file list...]
Main options (not all may apply)
-A, --auto Output format will be the opposite of the autodetected source
-D, --u2d Output will be in DOS format
--unix2dos Output will be in DOS format
-U, --d2u Output will be in UNIX format
--dos2unix Output will be in UNIX format
--force Ignore binary file detection
--safe Do not modify binary files
-?, --help Show this help message
--usage Display brief usage message
--version Display version information
--license Display licensing information
[input file list...] for each file listed, convert in place.
If none specified, then use stdin/stdout
You may not need to do that - your Cygwin shell may be set to ignore the carriage return that Windows adds to files. You WILL need it if you want to edit a Unix/Linux file in Notepad.
Generally speaking, if you see a file name in a Perl script, change it to "/cygwin/(drive)/path". You don't always need to do that - if you saw:
you could leave that alone, but if you see:
That would need changing:
That's in a different location. You could get away with just "/Program Files/Kerio/mailserver/mailserver.cfg", but to avoid missing something, I suggest just changing everything.
Note that we also introduced a space into the path ("Program Files"). You have to watch out for changes like that as the original script may not have bothered to quote things that will need to be quoted when spaces are part of the name.See Cygwin: using a path variable containing a windows path (with a space in it) for further discussion.
If your files were on D:, you'd use "/cygdrive/D/whatever" and so on. If in doubt, be specific.
Sometimes files exist on Windows with slightly different names. For example, a script might use "sendmail" from the Kerio mailserver directory. That script won't work on Windows because it's named "sendmail.exe" there. You'd need to either change the script or create a link from "sendmail.exe" to "sendmail".
Many Linux/unix Perl scripts use "system" to run operating system commands. Many of these will work in the Cygwin environment, but if you don't know that a particular command will work, you need to test. Sometimes you can fix a problem like that by writing a shell script that does the needed task. Other times you need to write the whole thing in Perl
The Linux/Unix script may reference Perl modules you don't have. CPAN is how you get them, but you need "make" from Cygwin setup too. You may run into other things you need; Google is your friend for those kinds of problems.
Note that I found CPAN to run much more slowly under Cygwin than it does on Linux or Mac OS X. It is so slow that I thought it was hung at times! You definitely need patience (something I don't have much of)
Help from me
If you are one of my Kerio customers (that is, you renew your licenses and buy new product from me), I will help you at no charge. Just send me the script you are trying to convert and tell me what I need to know about your environment
If you are NOT a Kerio customer, I might be willing to help you on a charge basis but my regular customers come first, always. If your project will require more than a few minutes of time, I might have to turn you down (unless you'd like to become on of my customers, of course).
Got something to add? Send me email.
Increase ad revenue 50-250% with Ezoic
More Articles by Anthony Lawrence
Find me on Google+
© 2012-10-14 Anthony Lawrence