The file getstat looks to be a JSON format file? It has some invalid control code characters when I copy it from here. Does it have that also in your file? After cleaning up the file (made it a single line of text) I could use jq to query it. jq is a tool to query JSON files from the Linux shell. So start by installing jq with command: apt install jq

To test if a file is in good format you can run: jq . [i]filename[/i]
If the file is good that will pretty print it's content. For your example file it does this for me (and it has color as well):

An example script that should work with your example file is below. I don't have any error check in here (does the file exists, did the jq command return any errors, does the script to invoke exist, and so on; exercises for the reader ) I assume the "goto scriptNN.sh" commands means to continue execution in that other script and not return to this script? If you want something else to happen, please describe in words.

Yeah, I copied text from linux to Windows so this is why there are some invalid code. I knew it was JSON but did not know anything about it. Thx. In the mean wile i found help with JSON about this miner (he generates getstat file), but i do not uderestand it very well. Thx for your help it is clear how to do it.

API Description.
Api establish the tcp connection and send through it json data, like a stratum protocol.
Every json request and response must be ended with new line symbol \n, this symbol used
as a sign of data end.

It's a bash file. Calling it with sh will break the script. Just mark the file as executable (chmod +x filename) and you can run instead (the ./ prefix is to indicate the teyt.sh file is found in the current directory; when running programs not in your PATH directories you must indicate where they are found):

Just so you (or anyone reading this) know, those errors came about because the [[ expression ]] testing syntax isn't in sh.

You needn't make a script executable to run it. Note that chmod -x <file> makes it executable for everyone, which is in general a potential security risk, although I doubt it's a concern with this particular script of course xD, still, it's worth keeping in mind. To make it so only you have execution privileges on a file, use chmod u+x <file> instead. You could run it with bash <script> without changing its permissions. You actually don't even need the shebang in a shell script unless you're going to ask the system to determine from the shebang which shell to use.

Lastly, #!/usr/bin/env bash isn't required (if you do use a shebang) as #!/bin/bash (or wherever bash is on your OS) is a more direct route. I consider the former method less secure, since I believe it picks up whichever "bash" is in your PATH. The caveat with the latter, is a slight drop in portability, so if a script is to support many different setups, then I'd assume the env route is probably the best one.

I know that was probably unnecessary as the thread is getting on a bit, but it gave me something to do. lol

Termy wrote:Just so you (or anyone reading this) know, those errors came about because the [[ expression ]] testing syntax isn't in sh.

\
Well, yes and no. The script was fine and the shebang line indicated it was a bash script. The mistake was using "sudo sh filename.sh" to invoke the script. That ignores the shebang line and indeed forces a script to be run by a different script interpreter. Yeah, that doesn't work very well Also, sudo is not need for parsing JSON files...

Termy wrote:Just so you (or anyone reading this) know, those errors came about because the [[ expression ]] testing syntax isn't in sh.

\
Well, yes and no. The script was fine and the shebang line indicated it was a bash script. The mistake was using "sudo sh filename.sh" to invoke the script. That ignores the shebang line and indeed forces a script to be run by a different script interpreter. Yeah, that doesn't work very well Also, sudo is not need for parsing JSON files...

Sorry, I forgot to quote. I was referring specifically to the [[: not found errors. Since the script was called with sh, as you pointed out, it resulted in those errors, because... [ insert my previous post ]

Perhaps we're meaning the same thing but when I read your "those errors came about because the [[ expression ]] testing syntax isn't in sh" I took that to mean "you shouldn't have used the [[ expression ]]" instead of "you shouldn't run bash scripts with sh, duh"