-2

I am not able to send commands to the server. However the connection is established and I am able to do the simple operations like "rm /usr/testfile". When I try to execute the command like "tail -f /opt/logs/applications/db/cbss.log >> cbsslog_tailed". Please help me to execute the tail command through java code.

  • I think you'll need to elaborate a lot on what you are attempting to do, starting with this "server" and how you wish to connect to it. Are you attempting to perform a remote login into a machine using a protocol like telnet or ssh and then execute certain shell commands? I'm afraid this isnt clear from the question. – Vineet Reynolds Dec 08 '10 at 09:27
  • Hi Vineet, Thanks for the reply.I am in the process of developing a tool to collect the logs(from the remote Solaris server) and to keep it in the local system(Windows). For this I am establishing a connection with the remote server using telnet and I am issuing a command using Runtime.Exec().All I wanted to know is that, is Runtime.Exec() the only one method to issue the command to the server or do we have some other methods also to issue the commands to the remote server?As I mentioned earlier I am not able to tail the log by issuing the command.Please give your advice on this. Thanks vineet – passionatebalu Dec 08 '10 at 14:38
  • However, I tried with the some other method as follws: public void sendCommand(String command) throws IOException{ if(command.endsWith("\n")) pw.print(command); else pw.println(command); pw.flush(); } – passionatebalu Dec 08 '10 at 14:40
  • Where Command is "rm /asdf" and I am able to successfully delete the file asdf in the server. But the same method is not working for tail command. Please suggest me on this. – passionatebalu Dec 08 '10 at 14:42

1 Answers1

0

It looks like you want to do I/O redirection in Linux via Java shell command execution support running from a server. Please refer to the link below on how to solve redirection problem:

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4

The sample programs in the link above are used in Windows environment. But, I think it could be ported to Linux without any problem.

eee
  • 1,043
  • 7
  • 5