Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been using bash for most of my system administration tasks. I also know a bit of perl.

Should I learn Python or Perl is better for system automation. So far from my experience learning perl has been easy.

share|improve this question
Should I buy a black server or a white one? They both do the job, so pick the one that best suits you. – John Gardeniers Mar 9 '11 at 10:20
You might be interested in reading "Minimal Perl". It shows how to use Perl as a replacement for many common shell utilities, and is targeted toward *nix users: – Joe Internet Mar 9 '11 at 11:38
up vote 9 down vote accepted

Short answer: learn both.

You are going to encounter both as a sysadmin, so you'll want to know how to read/troubleshoot/debug both.

As for writing scripts, I have used mostly Perl over the last 10 years for most of my sysadmin utility and "glue" scripts. Its regex syntax is really simple, and it lends itself quite well to extremely fast script development. This is quite important when you have to get something working on-the-spot.

Lately I have been making an effort to use more Python for the following reasons:

  • It takes a lot of discipline to write good Perl. All too often a "quick n' dirty" script has more features crept in over time, yet still implemented in a hasty manner. Before too long, you have a sprawling file of line noise which is a PITA to maintain.

  • Writing OO (or even reusable) code in Perl is not easy compared to Python. Believe me, in the long run you want lots of reusable code (and not cut-and-paste!)

  • Python's principles (import this) are much better suited to collaborating with others when compared to Perl's TMTOWTDI principle. If you've ever read someone else's Perl, you may know that it can be about the most frustrating thing to unravel. Python suffers from this unreadability problem far less due to its design. Worse even is when you encounter your own Perl after many years. You'll wonder at which point you must have blacked out.

  • Documenting is important if your code is going to be around a while. Writing docstrings in Python is much easier than writing pod markup in Perl. Easy enough that you might actually use it.

I still use Perl quite a lot, but it's now more for one-liners and "throwaway" scripts which will only run once. If I think I'm ever going to edit the script again, I consider Python instead.

share|improve this answer
Yes I have heard Python is good coding in OO. But for sysadmins is writing in OO required. I don't think I will be writing anything above 100 lines. – nitins Mar 9 '11 at 9:31
It's not required, no. You will encounter it, though, so it helps to be familiar with it. – Cakemox Mar 9 '11 at 9:39
+1 I most definitely agree with "Worse even is when you encounter your own Perl after many years. You'll wonder at which point you must have blacked out." And you can replace "many years" with 6 months! – Niall Donegan Mar 9 '11 at 11:42
As a sysadmin I regularly write over 100 lines. Usually once I hit 100 lines I start wishing I hadn't used bash :-) I'll use python (used to use perl) if I know if will be that long ahead of time. – Steven Mar 9 '11 at 18:50
I know this question's way past closed, but it pains me to see the 'perl is just line noise' thing still making the rounds. Shell scripting is line noise too, if you do it badly. Python is no less susceptible to the 'big ball of mud' design pattern than any other high-level language. Just Say No to implementation zealotry; focus on reliable, maintainable patterns in whatever language fits your environment. – Jeff Albert Mar 14 '11 at 18:50

It depends on what you're trying to do, and where you're trying to do it. All things being equal, and where you have no restrictions on your environment, can install whatever you want, and don't have to worry about interoperating with legacy code, feel free to pick the language that suits your personal preferences best.

That said, for sysadmin work, I do think Perl has an edge: it's installed on everything out of the box, and has been since roughly the dawn of time. If you're writing a system automation or management script and using only core Perl modules, you can be almost positive that it will run without modification everywhere in your heterogeneous UNIX environment, and can be extended fairly painlessly to Windows with an installation of ActiveState or Strawberry Perl.

Hope that helps!

share|improve this answer

I would recommend python. I know perl enough but am not an expert and my experience with python has been vastly superior. I think it depends on your needs but if its simply for system automation I would go the python route and forget about perl (for the time being).

Here is a great way to sink your teeth in:

With things like Fabric in development it can really make things easier:

Example from the page:

from fabric.api import run

def host_type():
    run('uname -s')


$ fab -H localhost,linuxbox host_type
[localhost] run: uname -s
[localhost] out: Darwin
[linuxbox] run: uname -s
[linuxbox] out: Linux

Disconnecting from localhost... done.
Disconnecting from linuxbox... done.
share|improve this answer
I favour func ( for these sort of tasks - it to is written in python and does not rely on ssh. – jamespo Mar 9 '11 at 10:11
nice one, shame it only supports fedora/EL – pablo Mar 9 '11 at 10:12

They're equivalent; for a home machine, which you use depends on which one you feel more comfortable in, but when working with others you should adhere to any established standards (if everyone else uses Python you shouldn't use Perl without good reason, and vice versa).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.