Jump to content

Grab output (log) from a known port on system


Butters

Recommended Posts

Hey, I;m having trouble debugging my system and need help getting the full log of what's going on.

I'm using Linux and run quite a few bots on one machine. I wanted to either redirect all bot output  logs to certain files or to keep the terminals open after the bot dies (this is the way I made stuff - kill the bot when it's done with System.exit(0);)

1. Grabbing output from a known debug port

Let's say bot uses debug port 5011. Tried using nc to listen for output on the mentioned port, though says that the port is already being used. Any better tools out there?

2. Keeping the terminal alive after bot dies

I start bots on their own terminal each time, using something like "xterm -e java -jar osbot.jar ........."

Now when the bot dies, the terminal closes, and bye bye all logs, error messages and etc.

I noticed that after osbot handles the login info it launches a new process or something to start the bot client

so something like "xterm -hold -e java -jar osbot.jar...." or "xter -e "java -jar osbot.jar;read" doesn't work as it stops doing stuff adter the login screen (even when I bypass it with -login flag),

 

So any ideas how to solve this?

In short I think I get some error message when I start a bot and I dunno what happened, the terminal closes immediatelly, overrding the log() method didn't help much either.

Link to comment
Share on other sites

I believe you need to connect a socket to the port you're debugging on and then use something like:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Debugger {

	private static Socket socket;
	private static OutputStream outputStream;
	
	public static void main(String[] args) throws UnknownHostException, IOException {
		socket = new Socket("127.0.0.1", 5123);
		outputStream = socket.getOutputStream();

		BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		String line;
		while ((line = reader.readLine()) != null){
			System.out.println(line);
		    }
	}

}

You can copy and paste that and it will be its on command line which should store everything. feel free to modify to print to a text file if you want. 

edit: 5123 is the port in there 

Edited by IDontEvenBot
  • Like 1
Link to comment
Share on other sites

20 minutes ago, IDontEvenBot said:

I believe you need to connect a socket to the port you're debugging on and then use something like:


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Debugger {

	private static Socket socket;
	private static OutputStream outputStream;
	
	public static void main(String[] args) throws UnknownHostException, IOException {
		socket = new Socket("127.0.0.1", 5123);
		outputStream = socket.getOutputStream();

		BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		String line;
		while ((line = reader.readLine()) != null){
			System.out.println(line);
		    }
	}

}

You can copy and paste that and it will be its on command line which should store everything. feel free to modify to print to a text file if you want. 

edit: 5123 is the port in there 

Thanks, will try this out. Somehow didn't think that OSBot runs a socket server for this :D

Link to comment
Share on other sites

48 minutes ago, nosepicker said:

Somehow the input stream is empty even though the bot is running and I connected successfully. Any ideas? Connected to the correct port ofc.

Didnt actually test it I just knew it wanted a socket connection on that port. After looking into it I cannot get anything to connect. Since it says it's waiting for transport dt_socket I think it wants us to use "jdb -attach 5005" in a separate cmd window to connect but that one doesnt connect either.

 

Link to comment
Share on other sites

38 minutes ago, IDontEvenBot said:

Didnt actually test it I just knew it wanted a socket connection on that port. After looking into it I cannot get anything to connect. Since it says it's waiting for transport dt_socket I think it wants us to use "jdb -attach 5005" in a separate cmd window to connect but that one doesnt connect either.

 

To my understanding, when osbot starts with -debug flag it starts a socket server on the specified port. So if OSBot is not running - you don't have where to connect. All fine and dandy, though somehow the inputStream is empty and doesn't provide me the log messages. All nulls. Maybe someone who messed around with this more could enlighten us?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...