Author Topic: Shell from lua  (Read 1572 times)

0 Members and 1 Guest are viewing this topic.

Offline Buzzkill

  • Respected Community Member
  • Full Member
  • *****
  • Posts: 176
  • Karma: 59
    • The Hundred Acre Bloodbath
Shell from lua
« on: June 07, 2015, 12:35:56 PM »
I know there has been discussions and projects around this in the past, but most roads I've walked down have turned into dead-ends.  I've written a small set of python scripts that let me do things globally across all of my servers (via the python-valve libraries that let me push commands to rcon).  I would now like to be able to call these python scripts from within ULX, so I can globally manage / globally communicate across all the servers.

The gm_python project looked interesting, but it appears dead and I can't find the source anywhere.  Does anyone have any leads on how to call either python or shell from within gmod lua  (without having to use a thrift or socket server as middleware, if possible).

Thanks.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Shell from lua
« Reply #1 on: June 07, 2015, 07:09:48 PM »
Care how hack-ish it is?
I wouldn't expect Source to let one run external code. That doesn't mean it can't be done, just that it would be an external module as you mentioned, or some exploit not corrected.
That being said, there's an easy hack that would work.
Run a looping python script.
Have it sleep 5-10 seconds between running. (Or longer, if you don't mind longer delay)
Have that script look for a text file containing input commands.
Have Lua output whatever commands you want to a .txt
The script, after running whatever is in that text, deletes it.
Process loops back again.

It's not pretty. But until you find the pretty answer, it would work.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Buzzkill

  • Respected Community Member
  • Full Member
  • *****
  • Posts: 176
  • Karma: 59
    • The Hundred Acre Bloodbath
Re: Shell from lua
« Reply #2 on: June 07, 2015, 08:47:02 PM »
Mhm... that would work.  And I can take it a step further and create individual files for each command (timestamp named, or some kind of sequence). The python listenloop would check for any files in a directory and process them.  This way I don't have to worry about server concurrently writing to a single command file and risking confusion on the part of the listenloop. Unlikely scenario, but always a concern if systems are writing to a common file.

Thanks!