当前位置:网站首页>[shell script] use menu commands to build scripts for creating folders in the cluster
[shell script] use menu commands to build scripts for creating folders in the cluster
2022-07-06 09:10:00 【chaolei_ nine thousand five hundred and twenty-seven】
Here's the catalog title
background
There is a need , You need to create the same directory on each host in the cluster , For example, to add a directory x, Then all hosts in the cluster need to create this x Catalog , And change the execution permission of the directory .
Realization
For ease of operation , Prepare to use menu commands to build options , The script selects the corresponding operation according to the options .
2.1 The configuration file
services_conf The configuration is as follows :
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 Script
#!/bin/bash
# Determine if the configuration file exists
function file_exist() {
conf_filename=$1
[ ! -f $conf_filename ] && {
echo "there is no conf file named $conf_filename"
exit 1
}
}
# Execute commands in the cluster
function create_dir() {
echo "ansible The order to be executed is $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 Start to deal with ........."
IFS=$";"
for sub_item in $service
do
# If the folder does not exist, create
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 Already exists ..............."
fi
done
echo "$service Finished processing ..................."
echo
done
IFS=$oldIFS
}
########## The script starts to execute
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. Create directory ; 2. sign out "
select option in " Create directory " " sign out "
do
case $option in
" sign out ")
flag=0
break
;;
" Create directory ")
echo -e "\033[31m Start creating directory ................\033[0m"
file_exist services_conf
main_op services_conf
echo
echo -e "\033[31m Finish creating directory ................\033[0m"
;;
*)
clear
echo " I'm sorry , Wrong option entered !"
echo "Please input a number: 1. Create directory ; 2. sign out "
;;
esac
#select
done
#while
done
边栏推荐
- After reading the programmer's story, I can't help covering my chest...
- 甘肃旅游产品预订增四倍:“绿马”走红,甘肃博物馆周边民宿一房难求
- The carousel component of ant design calls prev and next methods in TS (typescript) environment
- LeetCode:34. 在排序数组中查找元素的第一个和最后一个位置
- Pytest parameterization some tips you don't know / pytest you don't know
- Once you change the test steps, write all the code. Why not try yaml to realize data-driven?
- Leetcode: Jianzhi offer 03 Duplicate numbers in array
- opencv+dlib实现给蒙娜丽莎“配”眼镜
- Selenium+pytest automated test framework practice
- KDD 2022论文合集(持续更新中)
猜你喜欢
一篇文章带你了解-selenium工作原理详解
Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
【图的三大存储方式】只会用邻接矩阵就out了
Advanced Computer Network Review(5)——COPE
opencv+dlib实现给蒙娜丽莎“配”眼镜
[sword finger offer] serialized binary tree
IJCAI2022论文合集(持续更新中)
After reading the programmer's story, I can't help covering my chest...
[OC]-<UI入门>--常用控件-UIButton
数字人主播618手语带货,便捷2780万名听障人士
随机推荐
To effectively improve the quality of software products, find a third-party software evaluation organization
[sword finger offer] serialized binary tree
Intel Distiller工具包-量化实现2
A convolution substitution of attention mechanism
LeetCode:162. 寻找峰值
如何正确截取字符串(例:应用报错信息截取入库操作)
Ijcai2022 collection of papers (continuously updated)
Leetcode: Sword finger offer 48 The longest substring without repeated characters
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Cesium draw points, lines, and faces
LeetCode:214. Shortest palindrome string
Detailed explanation of dynamic planning
Advanced Computer Network Review(4)——Congestion Control of MPTCP
xargs命令的基本用法
在QWidget上实现窗口阻塞
Selenium+pytest automated test framework practice (Part 2)
数学建模2004B题(输电问题)
使用标签模板解决用户恶意输入的问题
I-BERT
CSP first week of question brushing