centos添加文件并依次传入对应id
Posted 纪仁旺
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos添加文件并依次传入对应id相关的知识,希望对你有一定的参考价值。
1、shell脚本:
#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脚本:
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()
以上是关于centos添加文件并依次传入对应id的主要内容,如果未能解决你的问题,请参考以下文章
java 怎样查询MYSQL数据库中的数据;根据id字段查询,获取id 对应的一行数据,并显示 在标签上。
ASP.net MVC 代码片段问题中的 Jqgrid 实现