章工运维 章工运维
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

章工运维

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • python

    • python基础

      • python基础知识
      • python基础较难的15个知识点
    • FastAPI

    • python每日练习脚本

    • python3给防火墙添加放行
    • python生成部署脚本
    • python将多个文件内容输出到一个文件中
    • 使用 Aligo 定时备份服务器文件
    • python监控日志文件并发送钉钉告警
    • python监控数据库脚本并发送钉钉告警
    • 使用python编写自动化发布脚本
    • 查询redis列表某个元素
    • centos7安装python3
    • python环境管理工具介绍
    • conda安装和镜像源配置
    • pip更换国内源
    • python爬虫
    • python环境启动服务报错缺少glibc库版本
    • 监控目录或文件变化
    • 批量更改文件
    • python引用数据库
  • shell

  • go

  • 编程
  • python
章工运维
2023-01-09

python将多个文件内容输出到一个文件中

生成多个文件脚本

#coding=utf-8
#import os
#import sys

sql1Script = '''
use scrm_%s;
-- 公司code需替换为相应公司的code
CREATE OR REPLACE VIEW `scrm_crm_contract` AS SELECT * FROM scrm_jishufuwu.`scrm_crm_contract` WHERE `company_code` = '%s';

-- 更新数据库版本.
INSERT INTO gf_db_version (MAIN_VERSION, DB_VERSION, SQL_NAME) VALUES ('R0028.000', 'R0028.000.000', 'R0028.000.000.0001.company.sql');

'''



def init_sql_execute():
    db_name=["Hitech", "Ztltech", "Bslm", "Yn"]
    # 替换字符串.
    for item in db_name:
        sql1 = sql1Script % (item, item)
        script = sql1

    # 生成脚本文件.
        fp = open("saas_sql_"+item+".sh", "w")
        fp.write(script)
        fp.close()
if __name__ == "__main__":
    init_sql_execute()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

将多个文件输出到一个文件中

#!/usr/bin/python
#encoding:utf-8
import os
# 目标文件夹的路径
filedir = r'/data/test'
#获取目标文件的文件名称列表  
filenames=os.listdir(filedir)
f=open(r'/data/test/aa.sh', 'w+')

for filename in filenames:
    filepath = filedir + '/' + filename
    for line in open(filepath):
        f.writelines(line)
    f.write('\n')
f.close()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
微信 支付宝
上次更新: 2023/01/10, 09:28:47

← python生成部署脚本 使用 Aligo 定时备份服务器文件→

最近更新
01
shell脚本模块集合
05-13
02
生活小技巧(认知版)
04-29
03
生活小技巧(防骗版)
04-29
更多文章>
Theme by Vdoing | Copyright © 2019-2025 | 点击查看十年之约 | 鄂ICP备2024072800号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式