话不多说,直接上code
python 脚本:test_mysql.py
#!/user/bin/env python
#coding=utf-8
import subprocess
def system_command(command):
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None, shell=True)
result = process.stdout.readlines()
return result
if __name__ == "__main__":
result = system_command('/root/test_mysql.sh')
print result
shell脚本:test_mysql.sh
#!/bin/bash
exe_secelt(){
HOST_NAME="192.168.165.101";
PORT="3306";
USER_NAME="root";
PASS_WORD="123456";
DBNAME="pear1.9.0-data";
TABLE_NAME="host";
HOST=$1;
select_sql="select * from ${TABLE_NAME} where name='${HOST}'";
mysql -h${HOST_NAME} -P${PORT} -u${USER_NAME} -p${PASS_WORD} ${DBNAME} -e "