Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have just migrated to a UNIX workstation. My memory of Bash shell scripts has faded since school and I find the syntax to be highly confusing. I am wondering what other scripting languages are used to automate tasks. The two most popular ones that I have heard of are Perl and Python.

  1. Which scripting language is most widely used by real world shops ?
  2. Which scripting language most closely resembles C/C++ syntax ?
  3. Is there another scripting language that I am not aware of ?

Thanks for your help,

Scott

share|improve this question
2  
This should probably be a community wiki. –  EBGreen Sep 4 '09 at 15:38
1  
I actually use PHP now for most system tasks. I'll put together a proper answer with this soon. It has lots of libraries built in, which is handy. –  Kyle Hodgson Sep 4 '09 at 16:15
    
Shell-intended languages do something that other languages might not; Which is manage and keep in check all children processes recursively ever spawned. The blog advertising Phusion Passenger explains why in detail: phusion.github.io/baseimage-docker In short, your scripts written in lang-x probably do not handle shutdown routines properly. Which is perfectly okay so long as you run them as children of a real shell process. Disclaimer, I am no expert. This information is only to the best of my understanding which may be flawed. –  ThorSummoner Nov 12 at 23:39

10 Answers 10

up vote 10 down vote accepted

To some degree it's a matter of personal preference. Perl and Python are definitely up there in terms of popularity.

To answer two of your three questions, though:

  1. I would guess that bash is most widely used, probably followed by perl. Just guessing though, dunno if anyone has done a survey. :)
  2. There are bazillions of scripting languages out there. :)

My recommendation is Python though. It's easy to read and write, immensely powerful, and there are tons of useful resources on the web for learning it, not to mention code that you can copy and re-purpose.

share|improve this answer
1  
I second that. I find Python easy to learn and able to do anything I throw at it as it's been in good old OS/2 days with REXX. –  slovon Sep 4 '09 at 15:47
2  
+1 for python...the power of C in a scripting language. You can make your scripts as simple or as complex as you want ;) –  KFro Sep 4 '09 at 23:01
    
on non NT systems the python module sh makes using python as a shell scripting language accessible; However if you run into edge cases (like multiprocessing) you'll have to learn the subprocess module which I to this day find too hard to just use. –  ThorSummoner Nov 12 at 23:20

Perl and Python are the obviously answers; but each of them is used to complete different tasks:

  1. Bash - Hands down the easiest to learn. With Bash scripts you run commands and manipulate the output.
  2. Python - Second easiest to learn. Python is way more useful than Bash since you can use Python to write full programs, and it's well supported by the community. Python is also extremely readable and easy to edit months later.
  3. Perl - The best of the three (for scripting), but easily the steepest learning curve. Has very good regular expression support (which is the main reason it's still in use today), and you'll probably run into a lot of Perl scripts over time. The main problems with Perl is code readability -- months after you write code you won't be able to figure out what it does. So you'd better comment heavily.
  4. Awk/Sed - Both very useful, but both very hard to learn. I'd suggest tackling these last, unless you're good at patterns.

Concerning which one to learn right now (since you presumably know none of them), I'd learn Python. It's the simplest and most useful to know.

And as for the answers to your questions:

Which scripting language is most widely used by real world shops ?

All of them, but I'd imagine that Perl has a little bit of an advantage here (being that it's been in use in system administration for much longer).

Which scripting language most closely resembles C/C++ syntax ?

Perl

Is there another scripting language that I am not aware of ?

Ruby, Tcsh/Csh, http://en.wikipedia.org/wiki/Interpreted%5Flanguage

share|improve this answer
1  
If you put some time into perl, you can write perfectly readable perl. People who write spaghetti code are too quick to blame Perl for their failures. –  Cian Sep 4 '09 at 16:10
    
I'm only speaking based on experiences as a sysadmin; I've had to maintain code other people have written that has been damn near impossible to read. Usually I end up just rewriting the code in Python. –  Michael Pobega Sep 4 '09 at 16:25

awk for small jobs, python for more-than-oneliners.

Python (if you don't use specific APIs and other platform dependent things) has a rich "standard library" which is available on all platforms where you get the python version in use. This is very nice as you can re-use your scripts easily and means your knowledge is a good investment even if you change your platform.

In our company we use python for all scripting, monitoring, ... and java for The application, and we're well off in heterogeneous environment.

share|improve this answer

I would say that perl and python are probably the two best alternatives. You can do a lot with sed and awk as well.

share|improve this answer

Sh (bourne shell), grep, awk and sed is always a good thing to get to grips again. Perl is excellent if you wan't a lot of text regexing and maintainability is not that important (not saying that it is not possible). Python; if readability is important to you. My preference is Python but all these tools are good for most thing you throw at it. You might want to reconsider you c/c++ syntax requirement, keeping stuck on it won't help you in the long run.

share|improve this answer
    
Thanks Martin. I've noticed (from samples on the web), that Perl bears a remarkable resemblance to PHP (although I'm sure it was Perl before PHP, historically). Is this a fair statement ? –  Scott Davies Sep 4 '09 at 15:55
    
PHP 1.0 was a perl script, so it's not coincidence :) –  Bill Weiss Sep 4 '09 at 21:43

If you are looking to learn something from scratch, it's probably best to (re-)learn bash.

Beyond that, perl and python are popular these days; I'm partial to perl, but my perl scripting style hasn't changed much since Perl 4 was out.

I'm not aware of any "c-syntax-like" scripting languages.

share|improve this answer

Perl, hands down, if only for the incredible resource of CPAN (http://search.cpan.org/). The benefit of using a scripting language with such a massive contributing community is that you are unlikely to ever need to invent something yourself.

Perl also has the benefit of being as complex as you need for the current situation. You can treat it as a simple scripting language for quick administration or single purpose scripts, but you can use object oriented concepts or extensive meta object systems when you want to create larger, easy to maintain applications (like daemons, servers, clients).

The differences among the scripting languages alone aren't severe enough to pick a clear winner, but you should primarily look at how easy it will be for you to find information on topics you care about.

Perl syntax can also be strikingly close to C, as long as you can get around the lack of typing and the sigils; advanced perl use would come naturally as you eventually learn the strengths of the language.

And for naysayers on the readability front: you can write hard to read code in any language. If you look back at your code from 4 months ago and can't understand it, you're doing something wrong.

p.s. This post was filled with links to various administration friendly modules on CPAN, but apparently new users can only post one link, so use that CPAN link to search for things like 'CVS' 'SVN' 'Cron' and 'Moose' (an extensive object system)

share|improve this answer
  1. most used: Perl, mostly for historical reasons. Python is widely available in all Linux and BSD distros (it's even installed on Mac OSX), and is far nicer to learn/program. Of course, once you get the syntax, Bash is simpler for almost anything that you could do at the command line. After all, it is the command line.

  2. C syntax: there's csh, but you can easily install TCC and use real C as scripting language, compiled from source in less time than other languages startup.

  3. other scripting languages: lots! Lua, Ruby, JavaScript...

share|improve this answer

You should be using a combination of all of those where it is appropriate. I really dislike perl ( readability ), but it's good for a lot of things. Python on the other hand was something new to me in terms of system administration, until i had to manage ( and still have to ) a few KVM machines. Starting, stoping, saving, loading, migrating all those machines via script became reality after 1 hour of messing around with libvirt's python bindings.

Last but not least i wouldn't use perl or python if i have to , let's say, dump all databases from a mysql server every night ( each database in it's own dump file ), tar them and rsync that to some other server. Why ? Because it's faster and easier to write it in bash :)

In the end, you should use whatever language fits your current task best and don't use only a given scripting language just because you like it most.

share|improve this answer

I like ruby. It's simple and easy to program with. There's an excellent book on system administration using ruby.

Ruby is used in several configuration management systems (capistrano, chef, puppet) and last version of metasploit.

You can use rush, a replacement for the Unix shell with ruby syntax and do things like this:

local = Rush::Box.new('localhost') 
remote = Rush::Box.new('my.remote.server.com')     
local_dir = local['/Users/adam/myproj/']
remote_dir = remote['/home/myproj/app/']

local_dir.copy_to remote_dir
remote_dir['**/.svn/'].each { |d| d.destroy }
share|improve this answer
    
Thanks chmeee. I had no idea you could use Ruby for sysadmin - I always thought it was web-centric. I'm looking for something in use at most organizations. Is it fair to say that Ruby for sysadmin is still too bleeding edge ? –  Scott Davies Sep 4 '09 at 15:58
1  
Shell/Perl are the only two languages that you can reliably find installed everywhere. Python's probably the next most common, with ruby running a very distant fourth (actually, probably fifth, behind awk). –  Cian Sep 4 '09 at 16:12
    
@ScottDavies PHP and ASP.net are the only web-centric languages I know of; even Javascript designed to run exclusively on the web has matured past being the lackie for form validation. However you can dispatch html with any language, even bash apparently. –  ThorSummoner Nov 12 at 23:24

Your Answer

 
discard

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.