views:

167

answers:

12

Sometimes I find myself needing to do something that could be automated or could be manual. E.g. I just ran a particular script 8 times, making a small change in between each run. I certainly could have written a script that would have automated this, but in this instance I decided it was quicker to just run it manually each time.

But sometimes I realize after I've put a bunch of time into doing something manually that I'd have been better off automating it in the first place.

Any suggestions for rules of thumb that would help me decide, before I start some repeated process, whether it's worth investing the time to write a script to automate it?

For clarification: the kinds of things I'm talking about are sysadmin-type stuff like moving files around, renaming things, etc. and DBA-type stuff such as running a SQL script to import certain data (this is what I was doing today). Note that I'm a developer, not a sysadmin or a DBA.

+3  A: 

Reasons I have for scripting include

When:

  • you do it the second time

  • it becomes more than one step

  • it's easy to get wrong

  • it's easy to forget how to do it manually

Matt Lacey
+8  A: 

I'm a fan of the "Three Strikes and you Automate" rule, as described at that link.

JosephStyons
Awesome. Describes exactly my sentiment. Its going up on my desk right now.
Preet Sangha
+1 I always follow this rule, and I hadn't realised someone had encapsulated it so nicely
Brian Agnew
+1  A: 

If there is one system administration truism, it is this: no simple sysadmin task is fun more than twice. If you find yourself doing a simple dull task more than twice, automate it.

-- http://www.ibm.com/developerworks/linux/library/l-punix.html

Noah
A: 

My rule is easy: In the long run, will I save time doing it manually or writing the script.

If you need to perform a specific task a few times only and then never again, it's probably not worth writing the script. But if you will need to perform the task repeatedly with only minor changes, scripting it will save you time.

Manu
+4  A: 

Don't just consider the time savings you may or may not see in automating process. Also take into account the likelihood that running a process manually may result in errors.

Done properly, an automated process should minimize the chance of error. This might cause you to automate even if it doesn't result in a net time savings.

Of course the flipside to this is if a process is running automatically, be sure to keep tabs on it to make sure it hasn't gone off track.

Jay Riggs
+1  A: 

Automation reduces source for errors if it's always the same set of operations that you perform repeatedly.

When I started with one of my (asp.net) project a couple of years ago, I had a manual release process that covered 3 written pages. Step by step I migrated that work into a build batch file (with command-line options etc to select single operations or everything).

Once the script was done, it performed flawlessly and it saved me an hour of manual work for each run.

And sometimes, it's only the fun of writing a script ;)

devio
+1  A: 

This is a site for developers.

If you think that you might need to do the same thing again, then automate it right now. But don't forget laws like YAGNI (You Ain't Gonna Need It) and avoid spending too much time on the automation. Just get something that works for you now with a little bit of coaxing.

Next time around, refactor and improve it, but only a bit. Remember YAGNI.

Third time around, try and get it in a nice little package where you can give it some inputs, and it will run to completion do sensible things on error conditions and log the errors.

And hopefully, you aren't using shell scripting but a real scripting language like Python where you can tweak the code and improve it ever time you use it, until it becomes a full-blown automation framework able to run remotely and manage thousands of servers from one invocation.

Michael Dillon
A: 

Good programmers tend to be lazy, in that they try to do things with the least expenditure of effort and time. So if it'll save total time effort, it may be worth it.

Loadmaster
+1  A: 

My rule of thumb:

  • if it feels tedious, spend a moment thinking aobut how you might automate it, how much work that would be and how much work it could save you.
  • If it would be very easy to automate or would obviously save a lot of work, start automating right away
  • If you decided not to automate and doing it manually becomes painfully tedious, or if you decide to automate but run into difficulties, think again, longer this time.
Michael Borgwardt
A: 

My rule is this: script it when it becomes something that you no longer want to have to think about. If you're still doing it mindfully, still learning something about the process, or still particularly interested in the results, don't script it. But if it's become something that you just HAVE to do to get something done, and doing it is a chore, script the hell out of it.

McWafflestix
+1  A: 

Besides the obvious, one reason for writing a script is because the act of writing a script is more fun than doing the task even once -- and you may learn something in the process.

For many geeks, doing something clever, fun and interesting outweighs any other benefit; so in this case, automating the task may well meet those criteria, even if takes takes longer than doing the tasks manually!

Steve Melnikoff
+1  A: 

M...man...manually?

Hold on... {taps feverishly away on dictionary.com... gasps... weeps silently to self...}

I need a drink.

inked