当前位置:网站首页>[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
边栏推荐
- Super efficient! The secret of swagger Yapi
- SimCLR:NLP中的对比学习
- Redis之Bitmap
- LeetCode:673. 最长递增子序列的个数
- Using label template to solve the problem of malicious input by users
- LeetCode:41. 缺失的第一个正数
- Intel distiller Toolkit - Quantitative implementation 3
- Mongodb installation and basic operation
- [sword finger offer] serialized binary tree
- Leetcode problem solving 2.1.1
猜你喜欢

LeetCode:124. 二叉树中的最大路径和

Pytest参数化你不知道的一些使用技巧 /你不知道的pytest

I-BERT

Export IEEE document format using latex

Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges

Redis之五大基础数据结构深入、应用场景

UML圖記憶技巧

LeetCode:124. Maximum path sum in binary tree

Once you change the test steps, write all the code. Why not try yaml to realize data-driven?

Pytest's collection use case rules and running specified use cases
随机推荐
Multivariate cluster analysis
[oc]- < getting started with UI> -- learning common controls
Super efficient! The secret of swagger Yapi
Export IEEE document format using latex
[text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth
LeetCode:394. String decoding
Intel distiller Toolkit - Quantitative implementation 1
[OC]-<UI入门>--常用控件-UIButton
Intel distiller Toolkit - Quantitative implementation 2
UML diagram memory skills
I-BERT
Intel Distiller工具包-量化实现3
【shell脚本】——归档文件脚本
A convolution substitution of attention mechanism
LeetCode:498. Diagonal traversal
[OC foundation framework] - [set array]
Leetcode problem solving 2.1.1
LeetCode:剑指 Offer 42. 连续子数组的最大和
Advance Computer Network Review(1)——FatTree
LeetCode:26. Remove duplicates from an ordered array