当前位置:网站首页>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
边栏推荐
- My deployment notes
- Erudite Valley Learning Records] Super summary, attentive sharing | common APIs
- Svg understanding and drawing application
- 静态和浮动路由
- DOM window related data, operations & BOM operations
- Pictures are adaptive to the screen
- VNC Timed out waiting for a response from the computer
- 视频格式基础知识:让你了解MKV、MP4、H.265、码率、色深等等
- [learning records of erudite Valley] Super summary, attentive sharing | collection
- Media set up live broadcast server
猜你喜欢

Results fill in the blank shopping list (teach you to solve it with Excel)

metasploit渗透ms7_010练习

MOOC翁恺C语言 第六周:数组与函数:1.数组2.函数的定义与使用3.函数的参数和变量4.二维数组

Icc2 analysis timing artifact analyze_ design_ violations

Applet custom components - data, methods, and properties

Firewall - iptables firewall (four tables and five links, firewall configuration method, detailed explanation of matching rules)

三层交换和VRRP

MOOC翁恺 C语言 第三周:判断与循环:2.循环

Remotely access the local website of services such as neo4j on the ECS

MOOC Weng Kai C language week 6: arrays and functions: 1. Arrays 2. Definition and use of functions 3. Parameters and variables of functions 4. Two dimensional arrays
随机推荐
Servlet
Layer 3 switching and VRRP
DOM - Events
Canvas drawing 2
爬虫学习总结
metasploit渗透ms7_010练习
DHCP服务
JSON notes
Media set up live broadcast server
Custom component -- communication between parent and child components
shell---条件语句练习
Implementation method of Bert
Shell script -- program conditional statements (conditional tests, if statements, case branch statements, echo usage, for loops, while loops)
Results fill in the blank. How many days of national day are Sundays (solved by pure Excel)
Bert的实现方法
VLAN的配置
一个定时任务提醒工具
在转化词向量之前先转化为AST再转化为词向量的实现方法
Joern's code uses -devign
[learning notes] knowledge management