Need a Python script to run in MID server (Linux OS)

alexgg57
Tera Expert

Hello Team,

 

I know, if MID server is on Windows OS, there is a possibility to run a Pyton script via PowerShell Flow Action.

However, I am interesting if we can call a Python in the MID if it's on Linux OS?

Any thoughts/ideas?

Thanks,

Alex.

 

1 ACCEPTED SOLUTION

DYCM
Mega Sage

Hi @alexgg57 ,

To execute python on MID Server, you can generate the ECC Queue record to invoke python script using the following code snippet:

 

var agent = "mid.server.MID_Server";
var eccQueue = new GlideRecord('ecc_queue');
eccQueue.initialize();
eccQueue.agent = agent; // replace with your MID server name
eccQueue.topic = 'Command';
eccQueue.queue = 'output'; // for an output record
eccQueue.state = 'ready'; // state must be 'ready'
// specify parameters in the payload
// skip sensor: skip_sensor
eccQueue.payload = '<parameters><parameter name="name" value="<path_to_your_python.exe> <path_to_your_python_file.py>"/><parameter name="skip_sensor" value="true"/></parameters>';


var sysId = eccQueue.insert(); 

 

Please remember to install Python on your Linux server, and specify the correct path in above code.

View solution in original post

7 REPLIES 7

Tushar
Kilo Sage
Kilo Sage

Hi @alexgg57 

 

Yes, I think you can run a Python script on a MID Server that is installed on a Linux OS.

As MID Servers are designed to execute various scripts and tasks, including Python scripts, on the host machine where they are installed, whether it's Windows or Linux.

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

alexgg57
Tera Expert

Thanks Tushar!

So how I can call PY script from a flow designer/action? I heard the Linux MID does not have a Powershell capabilities...

Am I wrong?

Thanks,

Alex

alexgg57
Tera Expert

Hello,

If anyone is using Python in MID and call it from FlowDesigner/Action?

I really have specific questions, but not sure if anybody uses...

Hi,

Yes, I am. I'm running MID server on linux. Using this to update knowledge article content with current information on local network devices.

On the MID server, I've setup a venv environment.

Then, I just create a bash script on the mid server using MID Server Script Files. Needed to login to MID server and then "chmod +x <script file name>". I've set the Parent to "SSH".

Filename:test.sh

#!/bin/bash

cd /opt/servicenow/mid/venv/test  ## change this to the directory of ven

source bin/activate

result =$(python test.py)  # python script to execute

echo $result

 

On the FlowDesigner, I just create a flow with "Create Record" step. Executing this from scheduled job.

Action: Create Record

Table: Queue [ecc_queue]

Fields:

Agent : mid.server.<mid server name>

Topic: Command

Queue: output

State: ready

Name: scripts/SSH/test.sh

Payload:<parameters><parameter name="skip_sensor" value="true"/></parameters>