python读取xml执行配置其中的脚本

#!/usr/bin/python
import xml.etree.ElementTree as ET
import sys
import os

xml_tree = ET.ElementTree(file='./test.xml')
tree_root = xml_tree.getroot()
cmd = tree_root.attrib['scriptName']

for child in tree_root:
    cmd = cmd + ' ' + child.attrib['param']

os.system(cmd)

读取的配置文件



<mode scriptName="./test.sh">
    <check param="-d db"/>
    <check param="-h disk"/>
    <check param="-p os"/>
mode>

调用的脚本

#!/bin/bash
cur_path=`dirname $0`;
cd $cur_path;

function func_check_os()
{
    echo $1
}

function func_check_db()
{
    echo $1
}

function func_check_disk()
{
    echo $1
}

while getopts :p:d:h:s: ARGS
do
    case $ARGS in 
        p)
              func_check_os $OPTARG
              ;;
        d)
              func_check_db $OPTARG
              ;;
        h)
              func_check_disk $OPTARG
              ;;
        *)
              ;;
    esac
done

你可能感兴趣的:(python,shell)