pthon代码实现在linux下对siebel服务器换包重启

siebel服务器的换包重启,需要输入多个命令,而且中间需要等待,经常停了服务忘了启动。之前项目的TA有写过一些shell脚本,启服务的,停服务的,包括自动换包重启的,但是因为里面有个mount目录经常出问题,所以平时也没有使用。最近刚好在学习python,就想通过python代码封装一下这些shell脚本,使交互页面看起来更加清晰。

其中主要是使用commands.getoutput来执行shell脚本,并获取output加以判断进行不同的逻辑处理。其中第一段代码是用echo命令打印SIEBEL_HOME环境变量,如果为空表明不是siebel用户登陆的,跳出程序。调用时直接在CRT命令窗口中使用命令python /home/siebel/script/autoupdatesrf.py即可。
具体代码如下:

#!/usr/bin/python2
# coding: utf-8
import commands
import time
import sys


t = commands.getoutput('echo $SIEBEL_HOME')
if t:
    pass
else:
    print '请切换至siebel用户执行此代码,再见'
    sys.exit(0)


print '1 查看服务器状态'
print '*'*48
liststr = commands.getoutput('/home/siebel/script/listsbl.sh')
print liststr
stopflg = liststr.find('处停止') 
if stopflg > 0:
    print '    该服务器已停止'
else :
    print '2 开始停止该服务器'
    stopstr = commands.getoutput('/home/siebel/script/stopsbl.sh')
    print stopstr
    print '    我需要睡130秒,你去玩吧'
    time.sleep(130)

print '3 开始替换srf文件'
print '*'*48
repstr = commands.getoutput('/home/siebel/script/update_srf.sh')
nofileflg = repstr.find('No such file or directory')
if nofileflg > 0:
    print '    在目录/siebel/8.2.2.4.0/ses/siebsrvr/objects/chs下未找到名为siebel_sia_latest_chs.srf的文件,请查看后重试'
    sys.exit(0)
else:
    print repstr


liststr = commands.getoutput('/home/siebel/script/listsbl.sh')
stopflg = liststr.find('处停止')
if stopflg > 0:
    print '4 开始启动该服务器'
    print '*'*48
    startstr = commands.getoutput('/home/siebel/script/startsbl.sh')
    print startstr
    print '    我需要睡180秒,你去玩吧'
    time.sleep(180)
    liststr = commands.getoutput('/home/siebel/script/listsbl.sh')
    startflg = liststr.find('处启动')
    if startflg > 0:
        print '    该服务器已启动'
        print '5 开始产生浏览器代码'
        print '*'*48
        genbbrostr = commands.getoutput('/home/siebel/script/genbscript_chs.sh')
        existsflg = genbbrostr.find('already exists')
        if existsflg > 0:
            print genbbrostr[0:existsflg+14]
            print '    最新的浏览器代码文件夹已存在,无需更新'
            sys.exit(0)
        else:
            print genbbrostr

其中用到的shell脚本也都贴一下,

listsbl.sh如下:

. $SIEBEL_ROOT/siebenv.sh
list_server all

stopsbl.sh如下:

#!/bin/sh

. ~/.bash_profile > /dev/null  

#******************************************************
#Description: Stop Siebel Server Service 
#Note: Please use siebel user to run the script
#******************************************************

echo "************************************************"
echo "Stop Siebel Server"
cd $SIEBEL_ROOT
. ./siebenv.sh
stop_server all
reset_server -e $ENTERPRISE $SBLSERVER

update_srf.sh如下:

. ~/.bash_profile > /dev/null
T1=`date +%Y%m%d%H%M%S`

cp -p $SIEBEL_HOME/objects/chs/siebel_sia.srf $SIEBEL_HOME/objects/chs/siebel_sia.srf$T1
cp -p $SIEBEL_HOME/objects/chs/siebel_sia_latest_chs.srf $SIEBEL_HOME/objects/chs/siebel_sia.srf
chmod 755  $SIEBEL_HOME/objects/chs/siebel_sia.srf

startsbl.sh如下:

#!/bin/sh
. ~/.bash_profile > /dev/null
#******************************************************
#Description: Start Siebel Server Service 
#Note: Please use siebel user to run the script
#******************************************************

echo "Startup Siebel Server"
cd $SIEBEL_ROOT
. ./siebenv.sh
start_server all

genbscript_chs.sh如下:

##########################################################################
##
## Generating Browser Script
##
##########################################################################
echo "Generating CHS Browser Script..."

cd $SIEBEL_ROOT/bin
genbscript "$SIEBEL_ROOT/bin/chs/loyalty.cfg" "$SIEBEL_ROOT/webmaster/chs" CHS

cd $SIEBEL_ROOT/webmaster/chs
jsfiledirchs=`ls -tr | tail -1`
echo "$jsfiledirchs"
cp -r "$jsfiledirchs"  $SWEAPP_HOME/public/chs
cd -




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值