Minecraft Server Executing Scripts - python

I am working on a minecraft world space that can interact with a terminal shell and run commands on the computer directly. I intend to use not just the vanilla server but maybe craftbukkit or spigot.
Is it possible to create a listener on minecraft server.jar and wait for a certain command which executes a script on the computer itself?
Is there a plugin out there made for this purpose?

You can create a new plugin for Bukkit/Spigot (more information here).
In the onCommand-Method you can then call Runtime.getRuntime().exec("your shell command") to run commands in the linux shell (can also be used on Windows servers).
See also the Java documentation.

Related

It is possible to use the CMD to send commands in the active Maya window?

I am a beginner in Maya, and I wanted to run commands in a cmd in the active window of maya to modify things in the scene, like put a sphere for example, be in python
from pymel.all import *
sphere()
or MEL
polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1;
I found the mayapi, and I found several content related to "headless" (without the GUI), but I found nothing to run in the open window yet, maybe because I don't know the terms very much. I would like it to be in python, but if you know any solution in MEL you can put it here too!
Is there any way to do this without specifying the open document path?
You have four basic options for programmatic control of maya.
Running scripts inside the script editor in Maya. This requires that you have an open GUI maya instance running and you'd either type the commands yourself, or initiate scripts by loading and executing them in the script editor. This works fine for automating repetitive tasks but requires manual intervention on your part.
You can send individual commands to Maya over a TCP connection using the maya command port This is basically like connecting to another computer over telnet: you can control the Maya sessions but you'll be communicating entirely via text. It's commonly used, for example, by people who are writing scripts in Sublime Text to test them out in Maya without switching windows
You can run a commandline-only copy of Maya using the MayaPy python interpreter that ships with Maya and the maya.standalone module, which hosts a non-GUI maya session. That lets you excute python commands in a Maya without needing the GUI at all -- it's a common tool for automation tasks.
You can pass a script argument to Maya at startup with the '-c' (for "command") flag. Maya will open and run that script. For legacy reasons the commands are only MEL, not python, but you can get around that by using the MEL command "python" along with a Python command in quotes.
All of these are useful, the right one really depends on what you need to do. For long running tasks however #3 is probably the most reliable method because it's easy to iterate on and test.

How do I run a python script using an already running blender?

Normally, I would use "blender -P script.py" to run a python script. In this case, a new blender process is started to execute the script. What I am trying to do now is to run a script using a blender process that is already running, instead of starting a new one.
I have not seen any source on this issue so far, which makes me concern about the actual feasibility of this approach.
Any help would be appreciated.
Blender isn't designed to be started from the cli and to then keep receiving more commands from the cli as it is running. It does however include a text editor that can open text files and run the text block as a python script, it also includes a python console that can be used to interactively type in commands while blender is running. You may also find this addon useful as it lets you to run a text block in the python console, this leaves you with an interactive session that contains the variables as they exist at the end of the scripts execution.
There is a cli option to run blender as a python console blender --python-console - the gui does not get updated while this console is running, so you could open and exec several scripts and then when you exit the console, blender will update it's gui and allow interactive use, or if you start in background mode -b then it will quit when you exit the console.
My solution was to launch Blender via console with a python script (blender --python script.py) that contains a while loop and creates a server socket to receive requests to process some specific code. The loop will prevent blender from opening the GUI, and the socket will handle the multiple requests inside the same blender process.

Fabric - how to use an interactive shell on remote computer?

I am trying to use Fabric to run commands on a remote machine.
This works fine, until the command on the remote machine is interactive. In that case, Fabric return the interactive shell, but force me to type the info needed, while I am trying to send a command that does everything in remote, so I can automate the procedure.
Example:
from fabric.api import *
env.hosts=['myhost.mydomain']
env.user='root'
run(test1/myapp; exectask; exit)
I run a cli application on a remote machine, that uses interactive shell, so it is waiting for me to type the command (exectask); then once done, to exit, I call the exit command.
What happens now is that the app launch, Fabric show me the interactive UI and I still need to type exectask and after, exit.
How can I tell fabric to run that app, then pass the command to the interactive shell and then the exit to quit?
I see that Fabric has the prompt feature, but that's to ask the user to input data, while I want to just pass the commands and get the result back.
You might want to look into pexpect, a pure-Python module that works like expect. Essentially, it allows your program to spawn an external program or process, then control it just like a human was interacting with it. You program in what the program should expect to see (hence the name), then what action(s) to take.

How to debug long running python scripts or services remotely?

Pretty much what the title says, I would like to be able to connect to a python process running under paster or uwsgi and utilize pdb functionality.
Using winpdb, you can attach to a running process like this:
Insert
import rpdb2; rpdb2.start_embedded_debugger('mypassword')
inside your script.
Launch your script (through paster or uwsgi) as usual.
Run winpdb
Click File>Attach
Type in password (e.g. "mypassword"), select the process.
To detach, click File>Detach. The script will continue to run, and can be attached to again later.

Execute remote python script via SSH

I want to execute a Python script on several (15+) remote machine using SSH. After invoking the script/command I need to disconnect ssh session and keep the processes running in background for as long as they are required to.
I have used Paramiko and PySSH in past so have no problems using them again. Only thing I need to know is how to disconnect a ssh session in python (since normally local script would wait for each remote machine to complete processing before moving on).
This might work, or something similar:
ssh user#remote.host nohup python scriptname.py &
Basically, have a look at the nohup command.
On Linux machines, you can run the script with 'at'.
echo "python scriptname.py" ¦ at now
If you are going to perform repetitive tasks on many hosts, like for example deploying software and running setup scripts, you should consider using something like Fabric
Fabric is a Python (2.5 or higher) library and command-line tool for
streamlining the use of SSH for application deployment or systems
administration tasks.
It provides a basic suite of operations for executing local or remote
shell commands (normally or via sudo) and uploading/downloading files,
as well as auxiliary functionality such as prompting the running user
for input, or aborting execution.
Typical use involves creating a Python module containing one or more
functions, then executing them via the fab command-line tool.
You can even use tmux in this scenario.
As per the tmux documentation:
tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more
From a tmux session, you can run a script, quit the terminal, log in again and check back as it keeps the session until the server restart.
How to configure tmux on a cloud server

Categories