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])
复制代码