当前位置:网站首页>Shell--- circular statement practice
Shell--- circular statement practice
2022-07-28 07:10:00 【Xiaobai needs to know everything】
1. Use case Realize the judgment of good and bad grades :
read -p "your score:" score
case "$score" in
[0-5][0-9])
echo "failure"
;;
[6-7][0-9])
echo "normal"
;;
[8-9][0-9]|100)
echo "excellent"
;;
*)
echo "please input right score!"
;;
esacExecution results :
[[email protected] ~]# chmod +x ca.sh
[[email protected] ~]# ./ca.sh
your score:34
failure
[[email protected] ~]# ./ca.sh
your score:98
excellent
[[email protected] ~]# ./ca.sh
your score:67
normal2. for establish 20 Users ( Let me first create two examples ), The user prefix is entered by the user , The user's initial password is entered by the user , for example test01,test10;
read -p "Please input your usernames:" username
[ -z "$username" ] && echo "you must input the usernames!" && exit 1
read -p "Please input your passwd:" passwd
[ -z $passwd ] && echo the passwd could not be null! && exit 2
for i in `seq 2`
do
id $username$i &> /dev/null
if [ $? -eq 0 ];then
echo "the user is already exist"
else
useradd $username$i &>/dev/null
echo $passwd | passwd --stdin $username$i >/dev/null
id $username$i &> /dev/null
if [ $? -eq 0 ];then
echo $username$i is ok
else
echo $username$i is not ok
fi
fi
doneThe results are shown below :
[[email protected] ~]# chmod +x cu.sh
[[email protected] ~]# ./cu.sh
Please input your usernames:test
Please input your passwd:123456
test1 is ok
test2 is ok3.for ping Test refers to the host of the network segment , The network segment is input by the user , For example, user input 192.168.2 , be ping 192.168.2.10 --- 192.168.2.20
UP: /tmp/host_up.txt
Down: /tmp/host_down.txt
read -p "Please enter the network:" IP
for i in `seq 10 20`
do
ping -c2 $IP.$i &> /dev/null
if [ $? -eq 0 ];then
echo $IP.$i is UP >> /tmp/host_up.txt
else
echo $IP.$i is DOWN >> /tmp/host_down.txt
fi
doneThe results are shown below : Need to go /tmp/host-down File View output information ;
[[email protected] ~]# cat /tmp/host_down.txt
192.168.188.10 is DOWN
192.168.188.11 is DOWN
192.168.188.12 is DOWN
192.168.188.13 is DOWN
192.168.188.14 is DOWN
192.168.188.15 is DOWN
192.168.188.16 is DOWN
192.168.188.17 is DOWN
192.168.188.18 is DOWN
192.168.188.19 is DOWN
192.168.188.20 is DOWN4. Use for Realize batch host root Password modification , Success or failure must be recorded ; Tips : host IP In a file ,SSH: Implement public key authentication , Execute host commands in remote , Implement public key authentication
# ssh-keygen Generate a key pair on the master for management
边栏推荐
- As a result, fill in the birthday candles
- PXE无人值守安装管理
- Firewall - iptables firewall (four tables and five links, firewall configuration method, detailed explanation of matching rules)
- Standard C language learning summary 3
- codesensor:将代码转化为ast后再转化为文本向量
- Standard C language learning summary 9
- 1、 PXE overview and installation
- 静态和浮动路由
- JS data type detection and modification detection
- DHCP服务
猜你喜欢
随机推荐
Group management and permission management
Esxi community network card driver updated in March 2022
DOM - Events
MOOC Weng Kai C language week 5: 1. cycle control 2. multiple cycles 3. cycle application
Results fill in the blank. How many days of national day are Sundays (solved by pure Excel)
Small turtle C (Chapter 5 loop control structure program 567) break and continue statements
小甲鱼C(第五章循环控制结构程序567)break和continue语句
shell---sed语句练习
Standard C language learning summary 6
Svg understanding and drawing application
Shell script - sort, uniq, TR, array sort, cut, Eval command configuration
Esxi community nvme driver update v1.1
PXE无人值守安装管理
读取xml文件里switch节点的IP和设备信息,ping设备,异常显示在列表里
Standard C language summary 2
Shell--第一天作业
freemarker合并单元格,if、else标签的使用,null、空字符串处理
YUM仓库的搭建
Clock tree analysis example
DNS domain name resolution








