I have a shell script which executes a various of commands like killing processes, copying files via scp, performing remote commands via ssh and etc…
The problem is that this script is hard to maintain and hard to unit test.
Moreover, I want in the future to change it so it would work with xml config file, and I think that it cant be easily done with shell scripts.
So, I want to transform it to a java application, but just running many commands with ProcessBuilder doesn’t feel right.
On the other hand, searching for java solutions for each “problem” that today is easily solved in shell commands (like java ssh client, java API for linux processes and etc..), also doesn’t feel right.
EDIT:
I know for sure that my program will run in a linux environment, so cross platform is a non-issue here.
Any suggestion?
I’ve used many languages for shell scripting; from Python, PHP, to Java – and I keep coming back to using the right tool for the job.
In the linux world, bash scripting is usually powerful enough, and perl has lots of good OS support.
It has surprised some of our developers in the past, that you can actually build functions within bash scripts, hand around state and manage a lot of what you’d normally expect. It’s just another language, but with the command line at the heart of it.
UPDATE:
Another thing I’d add is follow the principle of least astonishment, which in this case means that you should write the code to be what those managing the system would expect. All too often I see Java programmers writing their deployment like Java programmers, not system administrators. If you’re going to be handing these scripts over to a system administrator / operations role, then they are likely to be more familiar with shell scripts than a Java program they would have to compile.
On another note – treat your shell scripts like proper code. Put it in source control (my whole /etc is under Git management), have a bug tracking system, etc. It makes maintenance much easier.