Instructing a MID Server to run a command can be achieved with the Command Probe.
The following is a Script Includes, MidServerCommand, which can help with that requirement. ServiceNow Developer site link.
Server Side Example:
var jsonEncodedResponse = new midServerCommand().execute("mid_server_name",
'echo "Hello ServiceNow"' /* Command to execute */,
'30' /* Time out in seconds*/);
var stdout = jsonEncodedResponse.stdout; // Response
var stderr = jsonEncodedResponse.stderr; // Error, if any
var command = jsonEncodedResponse.command; // The command that was executed