当前位置:网站首页>【shell脚本】使用菜单命令构建在集群内创建文件夹的脚本
【shell脚本】使用菜单命令构建在集群内创建文件夹的脚本
2022-07-06 08:58:00 【chaolei_9527】
背景
有一个需求,需要在集群内的各个主机创建一样的目录,比如要新增目录x,那么该集群内的所有主机都需要创建该x目录,并更改目录的执行权限。
实现
为了方便操作,准备使用菜单命令构建选项,脚本根据选项选择对应的操作。
2.1 配置文件
services_conf 配置如下:
test1/logs;test1/project-logs;test1/agent/logs
test2/logs;test2/project-logs;test2/agent/logs
test3/logs;test3/project-logs;test3/agent/logs
test4/logs;test4/project-logs;test4/agent/logs
2.2 脚本
#!/bin/bash
# 判断配置文件是否存在
function file_exist() {
conf_filename=$1
[ ! -f $conf_filename ] && {
echo "there is no conf file named $conf_filename"
exit 1
}
}
# 在集群中执行命令
function create_dir() {
echo "ansible 要执行的命令是 $1"
ansible all -m shell -a "$1"
}
function main_op() {
services_conf=$1
services_name=`cat $services_conf | grep -v "^#"`
oldIFS=$IFS
IFS=$'\n'
for service in $services_name
do
echo "service:$service 开始处理........."
IFS=$";"
for sub_item in $service
do
#文件夹如果不存在则创建
if [ ! -d /home/work/chao/$sub_item ];then
create_dir "mkdir -p /home/work/chao/$sub_item && chmod -R 777 /home/work/chao/$sub_item"
else
echo "$sub_item已存在..............."
fi
done
echo "$service处理完毕..................."
echo
done
IFS=$oldIFS
}
##########脚本开始执行
echo "Now ,the shell will be executed named $0.............."
PS3="Enter option"
flag=1
while [ $flag -eq 1 ]
do
echo "Please input a number: 1. 创建目录; 2.退出"
select option in "创建目录" "退出"
do
case $option in
"退出")
flag=0
break
;;
"创建目录")
echo -e "\033[31m 开始创建目录操作................\033[0m"
file_exist services_conf
main_op services_conf
echo
echo -e "\033[31m 完成创建目录................\033[0m"
;;
*)
clear
echo "对不起,输入的选项有误!"
echo "Please input a number: 1. 创建目录; 2.退出"
;;
esac
#select
done
#while
done
边栏推荐
- Intel Distiller工具包-量化实现2
- Marathon envs project environment configuration (strengthen learning and imitate reference actions)
- Leetcode: Sword finger offer 48 The longest substring without repeated characters
- A convolution substitution of attention mechanism
- LeetCode:26. Remove duplicates from an ordered array
- 【嵌入式】使用JLINK RTT打印log
- Navicat premium create MySQL create stored procedure
- Variable length parameter
- Using pkgbuild:: find in R language_ Rtools check whether rtools is available and use sys The which function checks whether make exists, installs it if not, and binds R and rtools with the writelines
- Intel Distiller工具包-量化实现3
猜你喜欢

广州推进儿童友好城市建设,将探索学校周边200米设安全区域

SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date

requests的深入刨析及封装调用

BN folding and its quantification

Advanced Computer Network Review(4)——Congestion Control of MPTCP

Esp8266-rtos IOT development
![[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)](/img/af/a44c2845c254e4f48abde013344c2b.png)
[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)

使用latex导出IEEE文献格式

TP-LINK 企业路由器 PPTP 配置

Problems encountered in connecting the database of the project and their solutions
随机推荐
LeetCode:剑指 Offer 42. 连续子数组的最大和
Guangzhou will promote the construction of a child friendly city, and will explore the establishment of a safe area 200 meters around the school
LeetCode:221. Largest Square
@Jsonbackreference and @jsonmanagedreference (solve infinite recursion caused by bidirectional references in objects)
LeetCode:214. Shortest palindrome string
LeetCode:673. Number of longest increasing subsequences
Computer graduation design PHP Zhiduo online learning platform
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
Export IEEE document format using latex
Detailed explanation of dynamic planning
TP-LINK enterprise router PPTP configuration
[oc]- < getting started with UI> -- learning common controls
LeetCode:394. 字符串解码
Improved deep embedded clustering with local structure preservation (Idec)
What are the common processes of software stress testing? Professional software test reports issued by companies to share
Intel distiller Toolkit - Quantitative implementation 1
What is the role of automated testing frameworks? Shanghai professional third-party software testing company Amway
Intel Distiller工具包-量化实现2
opencv+dlib实现给蒙娜丽莎“配”眼镜
LeetCode:387. 字符串中的第一个唯一字符