当前位置:网站首页>Shell exercises
Shell exercises
2022-07-26 01:36:00 【m0_ fifty-eight million nine hundred and sixty-three thousand o】
1. Use case Realize the judgment of good and bad grades
[[email protected] test]# vim score.sh
#!/bin/bash
read -p "please enter your score (0-100):" grade
case "$grade" in
8[0-9]|9[0-9]|100)
echo " optimal "
;;
6[0-9]|7[0-9])
echo " good "
;;
*)
echo " Bad "
esac
[[email protected] test]# chmod a+x score.sh
[[email protected] test]# ./score.sh
please enter your score (0-100):99
optimal
[[email protected] test]# ./score.sh
please enter your score (0-100):10
Bad
[[email protected] test]# ./score.sh
please enter your score (0-100):67
good 2.for establish 20 user
The user prefix is entered by the user
The user's initial password is entered by the user
for example :test01,test10
[[email protected] test]# vim user20.sh
#!/bin/bash
read -p " Enter user prefix :" u
read -p " Enter the user's initial password :" n
for i in {1..20}
do
useradd $u$i
echo "$u$i"
echo "$u$i:$n" | chpasswd
echo "Initial password changed successfully."
done
[[email protected] test]# chmod a+x user20.sh
[[email protected] test]# ./user20.sh
Enter user prefix :user
Enter the user's initial password :123
user1
Initial password changed successfully.
user2
Initial password changed successfully.
user3
Initial password changed successfully.
user4
Initial password changed successfully.
user5
Initial password changed successfully.
user6
Initial password changed successfully.
user7
Initial password changed successfully.
user8
Initial password changed successfully.
user9
Initial password changed successfully.
user10
Initial password changed successfully.
user11
Initial password changed successfully.
user12
Initial password changed successfully.
user13
Initial password changed successfully.
user14
Initial password changed successfully.
user15
Initial password changed successfully.
user16
Initial password changed successfully.
user17
Initial password changed successfully.
user18
Initial password changed successfully.
user19
Initial password changed successfully.
user20
Initial password changed successfully.3.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
[[email protected] test]# vim 10.sh
#!/bin/bash
read -p " Please enter a network segment :" n
for i in {130..140}
do
if ping -c 3 $n.$i &> /dev/null
then
echo "$n.$i is up" >> /tmp/host_up.txt
else
echo "$n.$i is down" >> /tmp/host_down.txt
fi
done
[[email protected] test]# chmod a+x ping2.sh
[[email protected] test]# ./10.sh
Please enter a network segment :192.168.223
[[email protected] test]# cat /tmp/host_down.txt
192.168.223.130 is down
192.168.223.131 is down
192.168.223.133 is down
192.168.223.134 is down
192.168.223.135 is down
192.168.223.136 is down
192.168.223.137 is down
192.168.223.138 is down
192.168.223.139 is down
192.168.223.140 is down
[[email protected] test]# cat /tmp/host_up.txt
192.168.223.132 is up4. 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
# ssh-copy-id -i 192.168.2.3
[[email protected] test]# vim iplist
192.168.168.132 22
192.168.168.21 2000
[[email protected] test]# vim 4.sh
#!/bin/bash
num=`cat iplist | wc -l`
for((i=1;i<=$num;i++))
do
ip=`head -$i iplist | tail -l | awk '{print $1}'`
port=`head -$i iplist | tail -l | awk '{print $2}'`
ssh -p $port [email protected]$ip echo 123 | passwd --stdin root
done
[[email protected] test]# chmod a+x 4.sh
[[email protected] test]# ./4.sh边栏推荐
- The gym closes 8000 stores a year. How does the studio that bucks the trend and makes profits open?
- "Yuanqi Cola" is not the end point, "China Cola" is
- Easyrecovery15 data recovery software with high recovery rate and high download volume
- [unity] random generation of two-dimensional cave map
- 服务器可用资源查询脚本
- 华为无线设备WDS配置命令
- 8、学习MySQL 创建数据表
- Leetcode 537. 复数乘法(网友思路,自愧不如)
- Mysql_ Note2
- FreeBSD bnxt以太网驱动源码阅读记录二:
猜你喜欢

网络之IP地址

Google gson usage details

Practice sharing of monorepo based on yarn1.x

Leetcode537. 复数乘法(可以,已解决)

4QAM、16QAM 调制与解调仿真电路,观察并分析QAM星座图和误码率曲线【matlab代码】
![[unity] random generation of two-dimensional cave map](/img/ec/7433f6e942fc3d0b03cac37ac87e7b.png)
[unity] random generation of two-dimensional cave map

第二届中国Rust开发者大会来啦,完整议程大曝光!
![[Unity] 二维洞穴地图随机生成](/img/ec/7433f6e942fc3d0b03cac37ac87e7b.png)
[Unity] 二维洞穴地图随机生成

Go operation excel library excel use

Arthas watch command to view the properties of objects in the array
随机推荐
iNFTnews | 假如这是元宇宙20年后的样子
Tutorial on principles and applications of database system (055) -- MySQL query (XVII): usage of mathematical functions
"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 personal problem sets
Fastjason handles generics
[Unity] 二维洞穴地图随机生成
Leetcode537. Complex multiplication (yes, solved)
Causes of signal degradation in optical fiber communication
记一次自定义 Redis 分布式锁导致的故障
[software development specification III] [software version naming Specification]
Zero copy of network file transfer
【Go】如何控制协程的最大并发数
"Weilai Cup" 2022 Niuke summer multi school training camp 2 k.[link with bracket sequence i] bracket sequence DP
Network performance evaluation tool ping/mtr
Tutorial on principles and applications of database system (054) -- MySQL query (16): usage of date time function
Docker advanced -mysql master-slave replication
Prime Ring Problem
Is it safe for Huatai Securities to open an account online? How to handle it?
电视机软件烧录
Ideal Path(UVA - 1599)
Introduction to API testing