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

The programming language I know most about is Java. Currently I have to write quite a lot of "shell scripts" to automate my servers. Is there something like a "Java Shell" so I can write the shell scripts in Java?

share|improve this question
If all you have is a hammer, everything looks like a nail. Perhaps it is time for you to learn some new programming languages, specially the ones better suited for your current job. – Juliano Feb 26 '11 at 15:27
Did you ever notice that hammers come in all shapes and sizes, so that you can choose one suitable for the job at hand? – John Gardeniers Feb 26 '11 at 20:17
I think the point is that, sometimes, we have to fit screws. – DutchUncle Feb 26 '11 at 23:28
Well, regarding the hammer: Standardization is/can be one of the key "success principles". Of course there's always something more specialized and more appropriate, but this adds a lot of overhead in most cases... My problem is, I actually do only need to prototype something. I am NO programmer I am more a "business economics" guys... So a java shell (with loose typing...) would have been great... Thanks for all your answers... – jens Mar 4 '11 at 13:28
There's a mighty big difference between using java as your command shell and using java as a scripting language. – tylerl Sep 8 '11 at 4:21
up vote 4 down vote accepted

You can get groovy and use groovysh. I've done some things with that, but I find perl or bash/sh the most useful for doing admin scripts. An application language like Java adds a lot of overhead when all you need to do is execute OS commands and search text.

share|improve this answer
+1 for Groovy. It allows you to access the JVM and the full Java API, albeit with Groovy syntax. But if you're a Java developer then it's not that hard to get into. One of the big pushes for Groovy is the ability to write system independent scripts - for deployment, for testing, for anything. Best part - works on Windows, Linux and OS X without changing source. Oh, and yes you could use Cygwin on Windows to run nix based scripts but then you'd have to deal with Cygwin (not fun). – Mike Feb 28 '11 at 15:42
Actually it's true that it is very hard to replace bash scripting with groovysh. But its the step in the right direction and it seems there are some (although discontinued attemepts) to make it work more like a real shell (for example "grash")... In the End I will have to learn bash. But I hadnt heard of groovysh and I think its the best attempt to having a "java shell"... – jens Mar 4 '11 at 13:23

There is no real requirement that "shell scripts" have to be written in a shell language, you could do everything with C or even Assembler, if you like that.

In the context of shell scripts, the shell is nothing more than an interpreter for a programming language, just like Perl or PHP, but heavily optimized for the kind of work you mostly do with a shell script.

In the long term, I would suggest that you learn bash or something, which isn't really difficult because shells are very limited in their abilities so that there isn't too much to learn.

share|improve this answer
The main issue with writing administrative programs in a language other than c or a shell is making sure the runtime is available for your language. Most Linux systems come with bash, csh, perl, and sometimes python at install time, but they won't have java. – Jeff Strunk Feb 26 '11 at 20:14

Some of the lighter jvm languages have shells, but those are front-ends to the interpreter, not custom dialects for sysadmining. A good system shell needs to have excellent process and file descriptor support and have concise syntax and builtins, and I don't think that exists in Java.

You can mix programming with scripting with things like chef, puppet, vlad, and the like, but that means learning bash scripting first, because those languages, quite sensibly, delegate commands to the shell. Languages like Ruby, Perl and Python are less verbose and you'll see them used a lot. Java's verbosity and some of its core values (do everything in the jvm, don't leave the ide) make it very ill-suited to the task.

share|improve this answer

Yes, there is. I have been using BeanShell from time to time, even though it is not under active development at the moment. It is an interpreter for standard Java syntax and also comes with a graphical interpreter / environment, if required.

You could write your shell scripts as described in the BeanShell docs, but you would have to make the Beanshell jar file available to your Java installation for this (e. g. put it into the /ext/lib folder of your JRE installation), otherwise java will not find the bsh.Interpreter class.

However, I would also recommend to take a closer look at your shell scipting options (you did not mention your environment, but TiZon's recommendation with bash is cool when using Linux). Using a full-blown general-purpose programming language like Java will only get in the way when trying to be productive with shell-like tasks, e. g. moving files around, invoking commands and the likes.

share|improve this answer

You should probably take a look at Bash Scripting.

share|improve this answer

Yes, add the beanshell .jar into your Javahome/jre/lib/ext directory and then you can launch scripts like so:

java bsh.Interpreter myscript.bsh
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.