0 Members and 1 Guest are viewing this topic.
- In cases like https://github.com/Krush206/soldat-shell/blob/main/rcon_balancer#L91 why not use $( $( ) ) type nested shell execution as opposed to backticks which you had to escape?
- It seems like /tmp is hard coded in various places, might be helpful to make that customizable
- Have you considered the possibility for shell injection, eg if a player has malicious characters in their names?
It looks like the main loop of these scripts is an infinite busy-wait where you check for recognizable commands in /tmp/cmds, and if there are any you take action and immediately wipe the file. I have a few concerns with this approach:- with each iteration of the while loop (numerous per second as there are no sleeps) you'll be spawning off numerous `grep` processes, especially if none of them match (each elif). This would consume excessive resources- if there are many incoming messages at once, some of them will get dropped/ignored as the relevant `grep` might miss themInstead, why not find a way to pass netcat's stdin and stdout to your script's stdin and stdout, and operate on incoming lines as you receive them, using `while read line` or similar? That way you aren't busy waiting (as each loop iteration will block on reading an incoming message), won't drop messages, and will consume far fewer resources.
When writing Bash script I cannot recommend ShellCheck enough. It checks your code for best practices and errors. There's command line version and many text editors support it, at the very least I know for sure that Visual Studio Code does support it.
Backticks are old and some shenanigans can happen with them and they are still there only for backward compatibility afaik.
Instead, why not find a way to pass netcat's stdin and stdout to your script's stdin and stdout, and operate on incoming lines as you receive them, using `while read line` or similar? That way you aren't busy waiting (as each loop iteration will block on reading an incoming message), won't drop messages, and will consume far fewer resources.