Feb-26-2019, 01:57 AM
I want to execute a python script from a bash script. But I cant import the mysql.connector module when running the script from snmpd. If I run the python or the bash script manually it works fine. But when I run it through snmpwalk I got the following error.
Error:Traceback (most recent call last):
File "parser.py", line 3, in <module>
import mysql.connector
ImportError: No module named 'mysql'
my phyton code "parser.py"#!/usr/bin/python import sys import mysql.connector try: cnx = mysql.connector.connect(user='******', password='*****', host='127.0.0.1', database='******') cursor = cnx.cursor() query = "SELECT `Valor`,`Tipo` FROM `snmp` WHERE `OID`='"+sys.argv[1]+"'" imp="0" tipo="INTEGER" cursor.execute(query) for (Valor) in cursor: imp=Valor[0] tipo=Valor[1] print(tipo) print(imp) cursor.close() except mysql.connector.Error as err: print(-1) else: cnx.close();my bash script "panel-current"
#!/bin/bash if [ "$1" = "-g" ] then echo $2 echo "STRING" python /usr/local/bin/parser.py $2 fi exit 0snmpd.conf
pass .1.3.6.1.4.1.2020.1 /bin/bash /usr/local/bin/panel-currentI already checked that it runs on any python version 2.7 and 3.5. I think there is a problem with user permissions and the service is not able to load the mysql.connector module. Can anyone tell me how to fix it?