how do you automate?
January 24, 2006 12:15 PM   Subscribe

I have loads of work. I dont want to do it no more (than once) With batch files, there are things that i could automate right now, but i want to get more complex, with loops and ifs and error handling and all the rest. What would be the most beneficial short term / long term routes, what do you do?

I suffer a mostly windows world, limited skills across the board, supporting a win2k network and associated office / SQL things and random windows apps. i have played with batch file, liked them but seem limited. There is windows script or jscript which i know little about, should I? or jump straight onto VB, or python or is that overkill.
posted by ugrndhg to Computers & Internet (18 answers total) 1 user marked this as a favorite
 
I would think it entirely depends on what you're trying to accomplish. Perl is wonderful for certain things, especially if there's a module for what you want to do. Sometimes you'll want a keyboard/mouse macro playback piece of software, and other times you'll want something entirely different. What's your task?
posted by odinsdream at 12:23 PM on January 24, 2006


I do very much the same thing, and I mostly use AutoIt and Python. AutoIt is brilliant for automating tricky GUI programs and simple scripting, and Python is great for the heavier lifting.
posted by pocams at 12:30 PM on January 24, 2006


I do a ton of this stuff in a windows environment using PHP. Perl is probably better, I can't speak from experience, but it's the sense I get. PHP however, is probably a little easier to learn. One of the best things about using PHP like this is the system() function. You can use PHP to create input strings for any program on your system that has a command line interface (I use it with antiword, pdftk, csdiff, etc). I'm not sure if PERL has this or not, but it likely does. It also has COM support so you can grab data from the office suite, etc.
posted by miniape at 12:34 PM on January 24, 2006


I believe you can run bash under Cygwin, which gives you all the *nix shell scripting stuff on Windows. Otherwise I'd go with Perl.
posted by IshmaelGraves at 12:50 PM on January 24, 2006


I'm in the same situation and use VB. If I was just starting today, though, it'd VB.NET or C#.NET.

I am not saying those things are better than the very fine products suggested by other posters. I'm just saying you want Windows scripting, those'll get you where you're trying to go.
posted by Lyn Never at 12:59 PM on January 24, 2006


like those responses. I've just found autoit and played a little with php, so i could be on the right track, it may be a couple of packages i'd need, for on the fly and more oft repeated tasks. Currently there is quite a database bent focus. I have a few SQL data tables come in from various locations overnight. Queries are run against this, and outputs occur in a variety of formats, batch files copy, email outputs, FTPs and mail merges all spout off the updated data ready for the morning. This does happen automatically, but everything is very loose, with little feedback from one application to the next. Mainly when things fail, i want it to know and fix, stopping an starting services etc.
posted by ugrndhg at 1:03 PM on January 24, 2006


I HATE perl passionately, but wish I didn't. We just got off on the wrong foot, and I haven't been able to recover. It looks like complete gibberish to the uninitiated. I do all my scripting in bash now, and that means fuck-all in a windows environment.

If you want to get into some serious scripting, make the effort to learn perl. Perl is powerful and ubiquitous. Once you have your perl chops, you can do anything from simple text processing to full-on web applications on any platform. If you actually want to control other applications' GUIs, you're probably looking for a different tool, but for any data processing, text or database, perl is definitely worth the time investment over the long term.

I learned VBscript because it was pretty easy when I was automating a modem dialer in windows 98, but I haven't ever used those skills again. If I had taken the same time learning to solve the problem using perl, it would have saved me countless hours later in life.
posted by team lowkey at 1:13 PM on January 24, 2006


You are right, IshmaelGraves, bash is, in fact, the default shell in cygwin. So you can write Unix shell scripts to automate tasks under windows. Hell, you can even run cron to manage them, if you like.
posted by wheat at 1:29 PM on January 24, 2006


i have felt myself drawn towards perl or python, although thought there would be an intermediary learning curve Whereas perl does appear to be complete nonsense, python looks like something i may be able to get my head around as a newcomer to scripting. Is perl a much better prospect, as python seems and i've heard you could get results fairly quickly, both learning it and implementing using?
posted by ugrndhg at 1:35 PM on January 24, 2006


Writing these paragraphs out of order, my apologies if the answer seems a little convoluted.

It might be helpful to know what type of tasks you're going to automate. Perl lends itself to text processing, for example, whereas shell is good for file manipulation...

Another huge second (fifth?) for Perl. It only looks like gibberish when it's written by someone who doesn't give a care about readability, but can appear very english-like as well. Pick up the O'Reilly book most appropriate to your level, or start a safari account to access them online instead. Perl is a HUGE friend to me and has earned its title of "swiss army chainsaw" many times over in my environment.

The if...then and other structures in the various UNIX shells often are cumbersome. I develop lots of looping and if...then structures right on the command line, but it's such a pain for anything longer than a one-liner. If you ARE stuck on the idea of using shell, read below:

Another option might be to use ksh (Korn shell). I believe Microsoft still offers a downloaded version of ksh for Windows that should work without all the overhead that Cygwin creates. I use Cygwin on my machines, but then again I'm a UNIX guy and use a lot more than just the shell from that huge piece of software.

Speaking of ksh for Windows, I think I recall seeing a build of bash available as a Windows executable a while back. Might be worth a look.

Finally, about half my shell programs use awk and sed in some form as part of their structure; if I took the time to learn more, I've been told they're almost full programming languages in and of themselves. I think I remember several years back that someone wrote a simple network monitoring system in one of those two languages. I imagine the learning curve would be significant if going this route for more than the most simple task.
posted by tkolstee at 1:57 PM on January 24, 2006


If you're deciding between learning perl or python, I'd say go with perl, if for no other reason than it is the tool of UNIX admins everywhere. If you ever find yourself moving to a UNIX environment, pretty much any script you are looking to write has already been written a hundred times by other admins, and you can save yourself a lot of effort. There's nothing wrong with python, but perl is the de facto language of system administrators.

It's going to be slow going for a while, but with big dividends in the future. If you don't have the time to spend right now, and want a faster ramp up, go with VB. If you want the most transferable skills, learn perl.
posted by team lowkey at 2:28 PM on January 24, 2006


I'm going to disagree with most of the people above and suggest going with python. In my experience, unix tools are always a little awkward on Windows. You'll be constantly running up against the fact that the Windows directory seperator is the Unix escape character, for example (try "dir /s/b | xargs" for a good example of the problem). The Windows versions of unix tools are often confused by drive letters as well.

Besides, the Windows programs rarely offer the stdin/stdout interface that perl and bash work so well with - any scripting interface is more likely to be COM or a straight DLL interface. Python has particularly good COM (and other windows API) support through the Python for Windows extentions, and a fantastic DLL interface through CTypes. The learning curve is a lot less steep, as well (not to mention the maintainance issues you face with perl or a unix shell port).
posted by bonecrusher at 5:10 PM on January 24, 2006


I love how there's all these people suggesting non-native tools, when VBScript is no harder to learn, comes pre-installed, and will work just fine. Check out the resources in the Microsoft TechNet Script Center, including the learn to script articles.

You say you're working in a Windows world. Why would you learn a language that requires you to install new, third-party software on all your servers? (I say "all" because I guarantee you'll find other uses for it.)

While you're at it, get a text editor that does contextual highlighting. I recommend Crimson, it's what I use.

Anyway, your ultimate solution will probably have as many scripts as you have batch files and other things now. But you'll know exactly what they all do, and you'll have much finer options for logging, error detection, and recovery. Just keep in mind that, for some of the steps, the best solution might just be the one that's already there. (As they say, if it ain't broke, don't fix it.)

"Python has particularly good COM (and other windows API) support..."

So does VBScript -- built in. No extensions, no software to install, on every major version of Windows.
posted by CrayDrygu at 5:54 PM on January 24, 2006


Perl will damage your brain. Go Python.
posted by SPrintF at 7:47 PM on January 24, 2006


I also suggest the cygwin/bash route.
posted by furtive at 8:14 PM on January 24, 2006


"You say you're working in a Windows world. Why would you learn a language that requires you to install new, third-party software on all your servers?"

On the other hand, Python runs great on Linux, Unix, and Mac OS X as well as Windows. Learning a good cross-platform scripting language will be useful across a broad range of environments, especially heterogenous networks with both Windows and non-Windows servers. Heck, a good sysadmin should eventually know several scripting tools. (All of this applies equally well to Perl and bash, for example.)

VBScript has advangates, but it's useless as soon as you have to deal with non-Windows hosts. (And once you start doing server-side work, Windows is actually a minority platform.)
posted by mbrubeck at 8:54 PM on January 24, 2006


AutoHotKey is free and simple and one big step up from batch files (and waaaay easier than programming in Python or Perl). But what would I know ... I'm no sysadmin.
posted by ademack at 9:09 PM on January 24, 2006


Exactly. As I said, VBScript will get the job done pretty easily (except if you're doing heavy processing of sql data), but if you have the time to spend, it'll be much more useful to learn skills that are transferable to other environments. From someone who says they "suffer a mostly windows world", I would expect they are likely to want to branch into other realms, but it's their job to support this Windows network right now.

I personally think perl will be more useful than python, based on my experience of being a sysadmin who moved from a homogenous Windows network to mostly linux and Mac networks. Alls I'm sayin' is I wish I had learned perl instead of doing batch files then VBScript then C++ then PHP then bash. Perl really is the language of sysadmins. It's got 10 times the following of python. If you ever end up working on someone else's network, chances are high that you're going to run into perl scripts. I have failed job interviews for not knowing perl. Never lost a job for not knowing python.
posted by team lowkey at 12:17 PM on January 25, 2006


« Older MIDI music software that outputs image sheet music...   |   Help me debunk... Newer »
This thread is closed to new comments.