当前位置:网站首页>If/for/while/case case case of shell
If/for/while/case case case of shell
2022-07-21 03:48:00 【Lalala001】
Often forget Shell grammar , Record here :
if
# Judge that the incoming parameter must be greater than 1
if [ $# -lt 1 ]; then
echo "[WARNNING] Please enter the file you want to sync !!"
exit 0;
fi
$# Indicates the number of parameters
$0 Represents the file name of the current script
$1 Represents the first parameter
$2 Represents the second parameter
$* Represents all parameters passed to a script or function
$$ At present Shell process ID. about Shell Script , It's the process of these scripts ID
for
for host in slave1 slave2
do
echo ==================== $host ====================
done
case
#! /bin/bash
case $1 in
"start"){
for i in master slave1 slave2
do
echo " -------- start-up $i Kafka-------"
ssh $i "/opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties"
done
};;
"stop"){
for i in master slave1 slave2
do
echo " -------- stop it $i Kafka-------"
ssh $i "/opt/module/kafka/bin/kafka-server-stop.sh stop"
done
};;
esac
while
Calculation 1-100 And
#!/bin/bash
i=1
sum=0
while [ $i -le 100 ]
do
let sum=sum+$i
let i++
done
echo $sum
Case study
1. Sync files 、 Script for folder
#!/bin/bash
# Judge that the incoming parameter must be greater than 1
if [ $# -lt 1 ]; then
echo "[WARNNING] Please enter the file you want to sync !!"
exit 0;
fi
# Define the absolute path of the incoming parameter
absdir=$(cd -P $(dirname $1); pwd)
# Perform the transfer
#2. Traverse all machines in the cluster
for host in slave1 slave2
do
echo ==================== $host ====================
#3. Traverse all directories , Send... One by one
for file in [email protected]
do
#4 Judge whether the file exists
if [ -e $file ]; then
#5. Get parent directory
pdir=$(cd -P $(dirname $file); pwd)
#6. Get the name of the current file
fname=$(basename $file)
ssh $host "mkdir -p $pdir"
rsync -av $pdir/$fname $host:$pdir # -a Indicates transmission in archive mode -v Represents the output details
else
echo $file does not exists!
fi
done
done
# How to use ?
# 1. Add executable permissions to the script
$ chmod +x /zlp/scripts/bin/xsync
# 2. Add your own script to the environment variable
$ vim /etc/profile.d/my_profile.sh
export PATH=$PATH:/zlp/scripts/bin
# 3. distribution /scripts Folder
$ xsync /scripts/
边栏推荐
- qlineargradient中坐标的含义
- 【深度学习】卷积神经网络最大池化运算
- Flink datastream API (XIV) Flink output to MySQL (JDBC)
- Qcombobox in pyqt5 realizes multi selection function
- 理解WGAN 和 Spectral Normalization(归一化)
- 理解Seperable Convolution
- 【CANN训练营】基于昇腾CANN平台的AI CPU算子开发
- MIMO-OFDM Wireless Communication Technology and matlab implementation (2) - Outdoor channel model under SISO
- Xcode compilation build number increases automatically
- 论文学习----URLLC benefit from NOMA (1)
猜你喜欢
2D目标检测综述之检测模型篇(二)
(5) Pyqt5 series tutorials: use pychart to design the internal logic of pyqt5 in the serial port assistant parameter options (II)
Realization of data warehouse technology
【2022年第一期 CANN训练营进阶班模型课】第一次大作业和附加内容
[cann training camp] AI CPU operator development based on shengteng cann platform
【深度学习】卷积神经网络最大池化运算
辨析Iteration、epoch及batchsize之间的关系
Pyqt5 uses custom tooltips to solve the problem of incomplete display of qtablewidget data
Flink datastream API (I) execution environment
建筑空间温度分布预测模型与温度曲线图绘制毕业论文
随机推荐
(4) Pytorch deep learning: pyttorch realizes linear regression
Use of Dameng DTS tool
微分与梯度的概念理解
李宏毅2020机器学习--P11 Logistic Regression
Flink datastream API (XIV) Flink output to MySQL (JDBC)
[cann training camp] AI CPU operator development based on shengteng cann platform
在Pycharm中打包(.py)文件成(.exe)文件
Li Hongyi 2020 machine learning notes -- P10 classification
论文学习--Resource allocation in URLLC with online learning for Mobileusers
MIMO-OFDM Wireless Communication Technology and matlab implementation (2) - Outdoor channel model under SISO
There is a lot of garbage on wechat on the computer side that can be cleaned up
SQL subquery
About encoding (ASCII / Unicode / utf8)
Opencv系列教程(一):Opencv读取指定文件夹图片、视频,调用摄像头
[deep learning] instantiate a simple convolutional neural network using MNIST data set
MIMO - OFDM Wireless Communication Technology and matlab Implementation (2) - outdoor Channel Model under SISO
Affairs (segregated sector)
SQL transaction
[ROS robot system] autonomous navigation + Yolo target detection + voice broadcast
Summary of flutter