0

I'm automating a test scenario which validates back end logs in remote server using JAVA & selenium. I need to implement a method which will used to connect to the remote server using the pem file and tail the logs . Then I'm using Stringbuffer to read that logs one by one and validate with expected output.

I have tried the Process API in java to execute the shell command to connect to the remote server. But it's not working .please help me with this. are there any other options to do this?

commands[0]= "ssh /path_to_pem_file.pem username@server_ip";
commands[1]="tail -f /carbon.log";
 Process p = Runtime.getRuntime().exec(commands);
  • First, I don't see the relation to Selenium in your post. Second, what are you trying to do? only execut "tail -f" on the remote host? or you want to extract the log file content? – Adi Ohana May 07 '19 at 16:19
  • Yeah this is not related to selenium but im using this method in automation to validate some logs during front end actions. So first i need to connect to the server to do that . That method is calling from test script. Is there a way to connect to the server with pem file? The way i used to do it might be wrong. Please correct me if im wrong – sanduni jayawardena May 07 '19 at 16:23
  • My main requiremnt is to read log files line by line which is in the remote server – sanduni jayawardena May 07 '19 at 16:24

1 Answers1

0

To connect to a remote host using pem, execute:

ssh -i "pathToPem" user@host

Take a look at: https://www.faqforge.com/linux/distributions/debian/linux-how-to-view-log-files-on-the-shell/ to get what you want from the log file.

And, look at: Is that possible to get file content continuously from remote server for fetching the log file in a "continues" way

Try using JSch

JSch is a pure Java implementation of SSH2 that helps you run commands on remote machines. You can find it here http://www.jcraft.com/jsch/, and there are some examples here http://www.jcraft.com/jsch/examples/.

Adi Ohana
  • 927
  • 2
  • 13
  • 18
  • When i manually executing this command in the terminal it’s working property. But when i use the same format inside java method its not working. Its not taking the pem file path. – sanduni jayawardena May 07 '19 at 16:32
  • It is probably syntax issue. Try use JSch. I just edited my answer with some examples – Adi Ohana May 07 '19 at 16:38