shell脚本调用python程序

shell中:python ***.py argv1 argv2 shell调用python脚本,并且向python脚本传递参数

如下: sjc=python $HOME/xtwh/kyxjc/shell/timediff.py $wy_web_jcsj $xtTime_sjc

shell脚本

#echo $wy_web_jcsj
	#echo $xtTime_sjc
        sjc=`python $HOME/xtwh/kyxjc/shell/timediff.py $wy_web_jcsj $xtTime_sjc`
	#echo $sjc
        if [ $sjc -gt 600 ] ; then
                echo "E|weblogic日志生成时间不正确,请联系技术人员|Wy_Web_Chk|wychk||"
        else
		num=`egrep "error|warn" $1 |wc -l`
		#echo $num
复制代码

python脚本:timediff.py


#! /usr/bin/python
# coding=utf-8

'''
Created on 2018-9-15
Target: diff time_monitor and time_now ,print  interval
@author: yujianfeng
'''

from datetime import datetime, tzinfo,timedelta
import sys

def timediff(time_monitor, time_now):

    d1 = datetime.strptime(time_monitor, "%Y%m%d%H%M%S")
    d2 = datetime.strptime(time_now, "%Y%m%d%H%M%S")

    delta = d2 - d1
    print delta.seconds

if __name__ == "__main__":
    timediff(sys.argv[1],sys.argv[2])
复制代码

转载于:https://juejin.im/post/5b9f3a8b6fb9a05d2c439e12

你可能感兴趣的:(shell脚本调用python程序)