Running a unix command

Hi guys,

I am trying to write a java application using Creator, having not written java code in a good few years now, well really since uni, however what I want it a GUI front end that allows the user to execute unix commands on servers by pressing buttons.

Now I have designed the front end, with the help of Creator, but not sure how to get the code to execute unix commands on remote terminals, I know the runtime API exists, but that is only for the environment that the java app is running on, which mite be the same server we want to run the commands on, but mite as easily be a different server.

Anyone help?

Thanks

[657 byte] By [liquidchilda] at [2007-11-27 10:48:02]
# 1

You can use Runtime.exec() invoking commands though ssh. You will almost certainly have to setup the ssh authentication to be though 'public key'.

You would do well to spend a lot of time reading and digesting http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .

sabre150a at 2007-7-28 22:23:58 > top of Java-index,Java Essentials,New To Java...
# 2

Is there security issues with me doing it this way? Would i be better deploying the app on each unix server and just using the runtime methods directly on that server?

liquidchilda at 2007-7-28 22:23:58 > top of Java-index,Java Essentials,New To Java...
# 3

> Is there security issues with me doing it this way?

Of course! But if you use ssh with a user id that does not have root permissions then there is less of a security issue.

> Would i be better deploying the app on each unix

> server and just using the runtime methods directly

> on that server?

If you mean should you deploy a server application on your server then yes, of course!

sabre150a at 2007-7-28 22:23:58 > top of Java-index,Java Essentials,New To Java...
# 4

Hi,

No thats not really what I meant, the application I am writing basically controls the starting and stopping of SunOne servers across different boxes. I wanted to have a central console that would allow you to deploy, start and stop servers, this is being written in jsp, java etc.

Now the option is to have the app deployed on one of these servers, but you would have a drop down list on the app front end to allow you to choose which server to start and stop, obviously if your don't it for the server which the app is deployed on, it would be a local command, however if your doing it on another app it would be a remote command.

Now the alternative is instead of allowing one app to control all servers, you deploy the app on each server and only allow it to control the server in which it is deployed.

Hope that makes sense. I have never really done SSH through Java, and its been a while since I have done Java, however do I just invoke the SSH through a third party program, like putty?

Thanks

liquidchilda at 2007-7-28 22:23:58 > top of Java-index,Java Essentials,New To Java...
# 5

>

> Hope that makes sense.

It makes a bit of sense though most application servers and Web servers have a web control interface anyway so I'm not sure what you gain by this.

> I have never really done SSH

> through Java, and its been a while since I have done

> Java, however do I just invoke the SSH through a

> third party program, like putty?

ssh is available as a command line application which you can invoke though Runtime.exec() but there are many Java ssh client libraries. Google is your friend.

I see no advantage to using putty for this. If you use Runtime.exec() then you don't need the GUI that comes with putty. If you use one of the Java ssh libraries then you won't even need ssh client installed.

One problem you may have with all of this is that your system admin people may not like having an ssh server running on each machine.

sabre150a at 2007-7-28 22:23:58 > top of Java-index,Java Essentials,New To Java...