美文网首页
python小脚本

python小脚本

作者: timar | 来源:发表于2019-06-20 15:45 被阅读0次

解压备份文件并重启jboss
服务器python版本2.7.5

myutil.py

'''
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import re
import shutil
import zipfile

## 解压文件到指定目录
def unzip_file(filepath, filedest):
    if zipfile.is_zipfile(filepath):
        fz = zipfile.ZipFile(filepath)
        for file in fz.namelist():
            fz.extract(file, filedest)
    else:
        print "not a zip file!"

reStart.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import re
import shutil
from myutil import *


files = os.listdir("/APP");
backupFiles = [];
for f in files:
    if os.path.isfile(f) and f.startswith("Backup_"):
        backupFiles.append(f);

file = backupFiles[len(backupFiles) -1];
print file;

app = re.search(".*_(.*)_.*", file).group(1);
print app;


print "准备删除本次安装文件"
if os.path.exists("/APP/" + app):
    shutil.rmtree("/APP/" + app);
print "删除成功";

unzip_file("/APP/"+file , "/APP/"+app);
print "解压文件成功"

os.system("nohup /opt/jbshome/jboss-eap-6.4/bin/standalone.sh &")
##  os.system("python /APP/script/zjostart.py -n " + app + " -c J")
print "应用启动成功"

相关文章

网友评论

      本文标题:python小脚本

      本文链接:https://www.haomeiwen.com/subject/hykjqctx.html