【centos添加文件并依次传入对应id】提兵百万西湖上,立马吴山第一峰!这篇文章主要讲述centos添加文件并依次传入对应id相关的知识,希望能为你提供帮助。
1、shell脚本:
#!/bin/bash
#auther:
function recreate() {
# shellcheck disable=SC2162
while read line
do
c_id=$(echo "$line"|awk -F : {print $1})
user=$(echo "$line"|awk -F : {print $2})
# shellcheck disable=SC1073
# shellcheck disable=SC2157
if [ -f "/Users/hhjie/gitlab.hhjie.top/hhjie/hhjie-devops/scripts/rebuild_openvpn_user/ccd/${user}" ]; then
rm -f /Users/hhjie/gitlab.hhjie.top/hhjie/hhjie-devops/scripts/rebuild_openvpn_user/ccd/"${user}"
echo /Users/hhjie/gitlab.hhjie.top/hhjie/hhjie-devops/scripts/rebuild_openvpn_user/ccd/"${user}文件已经删除"
fi
cat > /Users/hhjie/gitlab.hhjie.top/hhjie/hhjie-devops/scripts/rebuild_openvpn_user/ccd/"${user}" < < EOF
ifconfig-push 10.158.99.${c_id} 255.255.255.0
push "route 10.77.10.0 255.255.255.0 vpn_gateway"
push "route 192.178.0.0 255.255.255.0 vpn_gateway"
push "route 10.128.78.0 255.255.255.128 vpn_gateway"
push "route 10.15.107.0 255.255.255.0 vpn_gateway"
push "route 172.18.100.0 255.255.255.0 vpn_gateway"
EOF
echo "$user"账号已经创建
done < /Users/hhjie/gitlab.hhjie.top/hhjie/hhjie-devops/scripts/rebuild_openvpn_user/name2.txt
}
function main() {
recreate
}
main
2、python脚本:
#!/usr/local/env python3
import os.path
def remove_user():
all_user = os.listdir(ccd_dir)
for u in all_user:
per_file = os.path.join(ccd_dir, u)
if u.endswith(_client):
print(f"跳过删除${per_file}")
else:
os.remove(per_file)
def create_user():
for i in user_list:
print(i)
c_id = i.split(:)[0]
user = i.split(:)[1]
template_format = user_template.format(c_id)
path_join = os.path.join(ccd_dir, user)
with open(path_join, a) as f:
f.write(template_format)
if __name__ == __main__:
user_list = [
"31:chenhui",
"32:huxinyan",
"33:linhuipeng",
"34:liuchao",
"35:liuzhixing",
"36:sunxiangxiang",
"37:wangzhiwei",
"38:yanmingshun",
"39:zhangdipeng",
"40:zhaotongzhou",
"41:zhujia",
"42:yangjia",
"53:lijiachun",
"56:gaoxirui",
"57:xiekai",
"58:suyingying",
"59:yangke",
"61:zhengchengzhi",
"62:zhangqiang",
"63:shipengyu",
"64:houqinghua",
"65:zhangru",
"66:luoqiangqiang",
"72:hhjie",
]
user_template = """ifconfig-push 10.158.99.{0} 255.255.255.0
push "route 10.77.10.0 255.255.255.0 vpn_gateway"
push "route 192.178.0.0 255.255.255.0 vpn_gateway"
push "route 10.128.78.0 255.255.255.128 vpn_gateway"
push "route 10.15.107.0 255.255.255.0 vpn_gateway"
push "route 172.18.100.0 255.255.255.0 vpn_gateway"
"""
ccd_dir = "/Users/hhjie/gitlab.hhjie.top/hhjie/hhjie-devops/scripts/rebuild_openvpn_user/ccd"
remove_user()
create_user()
推荐阅读
- Mock工具介绍,为什么使用Mock()
- 数年转行撑了么“听话式“搬运工(挥泪总结(真香有图))
- nested exception is java.lang.IncompatibleClassChangeError: Implementing class(已解决)
- Spring 官方批处理框架真香!Spring 全家桶永远滴神!
- 优雅的实现 Excel 导入导出
- 笑出腹肌!有些程序员真会玩代码注释
- 解决Connecting to github.com 超时的问题
- 8年Java老鸟讲解, 事务的隔离级别,这篇很通透
- 详细讲解Spring中的@Bean注解