• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

how can i execute a ping command

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi experts,
can you help me on my problem,im trying to execute several command in a ssh server remotely,i'm stuck with some linux command because it gave me no output,im trying to ping a server(xxxx),server name is from the input of a user, and trying to run a command that would stop and start the database remotely...
sample command(/etc/init.d/postgresql restart;ping xxxx)
any help would be greatly appeciated,,
im stuck here for 2 days...thanks
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by wilfredo doming:
hi experts,
can you help me on my problem,im trying to execute several command in a ssh server remotely,i'm stuck with some linux command because it gave me no output,im trying to ping a server(xxxx),server name is from the input of a user, and trying to run a command that would stop and start the database remotely...
sample command(/etc/init.d/postgresql restart;ping xxxx)
any help would be greatly appeciated,,
im stuck here for 2 days...thanks



You cannot PING in Java, as far as I know, and I doubt you really need ping in Java.

Check this library Commons NET for common operations like checking a server is online .

Check this one Trilead SSH for Java for SSH operations.
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe a form of ping has been added to Java 5. Take a look at the isReachable() method of the InetAddress class. At minimum, this method should use the ping port to determine reachability.

Henry
 
wilfredo doming
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply,actually im already using trilead SSH in my project,i cannot use this command(sess.exec("ping l.getHostName()")),im looking for alternative solutions..and any idea on how the stop/start thing in SSH can be executed using sess.exec()??
 
Rancher
Posts: 4686
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
look up the System.exec() call, it can execute any generic shell command.

Whether that will be useful is a separate topic. Try it from a shell.
You may find that the server doesn't respond to the ping command, that firewalls block it, etc.

But if you can get a shell to do



then you can use System.exec() to do it.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Pat meant to say Runtime.exec().
And if you're using Java 1.5 or later you could also use ProcessBuilder.
 
wilfredo doming
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks,another problem is when i execute a certain command,it prompts me to enter the same password again,maybe for verification.this regards with the stop/start thing.i manage to execute it,but the output is not what ive expected...when the command is executed it goes straight to the next password,but it cannot get the value of my set password,then the program reads that i enter a blank password,which i want is to get the value of the password i set...
here is the output
STDERR password:
Password: su: incorrect password
STDERR:..failed
STDOUT:Starting PostgreSQL

i want to get the same password to be able to execute the command..

thanks,your help is much appreciated

[ August 27, 2008: Message edited by: wilfredo doming ]
[ August 27, 2008: Message edited by: wilfredo doming ]
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic