Sign in with
Sign up | Sign in
Your question

Cross platform scripting

Last response: in Linux/Free BSD
Share
January 3, 2009 8:17:13 AM

Forgive me for my sins, they pay my wages....


The new job I have is looking like it will involve a fair degree of fairly low level system administration, we have a lot of instances of the same stuff with different customisations for different clients. In order to make life easy I'm looking to automate as much of this as I can and over the past few days have found myself back in the world of batch scripting. Now this is on Windows systems and it is becoming very clear that old .bat files and checking error levels etc is just not going to cut it. Yesterday I spent a bit of time having a play with VB Script / WSH and having a good read up on Windows Power Shell. I have to say the power bit of power shell really does appeal, it might be MS but I have to say I was seriously impressed with it. The ability to query via inbuilt methods and export in a number of formats could be VERY handy.

The issue / question is this. I'm lazy, I'd like to learn one scripting language well and then use it in not just Windows but also Unix / Linux environments. I know I can plug plug a Perl module into WSH to allow me to script in Perl (something I've been running away from for a while as I find Perl an UGLY language!), likewise with Python. Trouble here is that they are non standard configurations so I could never deploy them at customers and none of my co-workers would be in a position to maintain them, likewise with Power Shell. VB Script would work well on Windows but then I'm screwed on the Linux side. This leaves Java Script... Can you script on Linux in Java script? I'm not talking web development here but system administration tasks, the sort of stuff you might do with a BASH script or a bit of perl.

Any other suggestions on how to approach this? I guess the real answer would be to learn the right tools for each platform but if I can reduce the learning curve and re-use bits of logic then that would be cool.




January 3, 2009 5:52:03 PM

You can't really use javascript outside the web browser on Linux or Windows as far as I know and even if you could, javascript would be a very poor choice.

Even Java as bad as it can be would be a better choice but would not be interpreted.

However a cross platform language like Perl, PHP or Python would be a much better choice, probably in the order listed.

You can also use shell with cygwin which is quite good, although others may object to it for various reasons. With cygwin you can also use native Perl, Python, PHP and several other languages.

Perl, PHP or Python are probably your best choices, since you already rejected Perl and Python, I suppose that leaves PHP.

Semper Fi :) 
January 3, 2009 11:33:09 PM

Not an option really, the main focus is on Windows and it will have to run on user PC's (internal customers). It HAS to be part of the standard distro and there is no way I'd get Cygwin under the radar. I might be able to get the Perl snap-in past the powers that be, but then I'd have to deploy that on users PC's for them to be able to invoke scripts locally. Might as well be VB Script for that side of things :( 

Seriously though - I just can not stand the look of Perl. I know it's bloody powerful but I just can't live with the hideous code and obscure string sequences. For the stuff that I will be running from my system I'm actually wondering if Power Shell might not be the answer. I'd strongly recommend that you take a look at it, I'm a cynic and I was blown away after reading a couple of papers... I know, I know... I'll say my hail Linus's later.

As for Java Script you can do pretty much everything you would with VB Script under windows. As I said it's rather confusing as you (like me!) instantly thought in terms of web page scripts - it's a totally different beast. Again worth a look, think VB Script meats Java and the WMI / COM interfaces. Hooks into just about every last part of the system.
Related resources
January 4, 2009 2:15:19 AM

Forget about cygwin, just use PHP.

PHP runs natively on Linux BSD Unix and windows.

:) 
January 4, 2009 2:53:43 AM

Seriously though Perl is a beautiful language.

Your code doesn't have to look like this

  1. @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
  2. @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
  3. ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
  4. close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print



Also vi can make ugly code look great have a look here ( caution 2MB file )


http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/(NoSPAM)index-pl.html

Remove the " no spam " for the correct URL

:) 
!