当前位置:网站首页>Shell fourth day homework
Shell fourth day homework
2022-07-25 11:23:00 【weixin_ fifty-one million eight hundred and eight thousand and 】
1、ping Host test , Check whether the host is alive ;
[[email protected] zuoye]# vim 1.sh
#!/bin/bash
ping -c2 192.168.40.128 &>/dev/null
if [ $? -eq 0 ];then
echo "is runing"
else
echo "not runing"
fi
~
2、 Determine whether a user exists ;
[[email protected] zuoye]# vim 2.sh
#!/bin/bash
read -p "input user name:" name
id $name &>/dev/null
if [ $? -eq 0 ];then
echo "$name is exist "
else
echo "$name is not exist"
fi
~
3、 Determine whether the current kernel major version is 3, And whether the minor version is greater than 10;
[[email protected] zuoye]# vim 3.sh
#!/bin/bash
main="`uname -r |cut -d . -f1`"
sub="`uname -r |cut -d . -f2`"
if [ $main -eq 3 ];then
if [ "$sub" -gt 10 ];then
echo "main is 3 and sub more than 10"
else
echo "main is 3 but sub less than 10"
fi
else
echo "main is not 3"
fi
4、 Judge vsftpd Is the package installed , If not, install automatically ;
[[email protected] zuoye]# vim 4.4.sh
#!/bin/bash
rpm -qa |grep vsftpd
if [ $? -eq 0 ];then
echo "The vsftpd is install"
else
yum -y install vsftpd
rpm -qa |grep vsftpd
fi
5、 Judge httpd Whether to run ;
[[email protected] zuoye]# vim 4.5.sh
#!/bin/bash
systemctl is-active httpd.service &>/dev/null
if [ $? -eq 0 ];then
echo "httpd is runing "
else
echo "httpd is not runing"
fi
6、 Determine whether the specified host can ping through , You have to use $1 Variable ;
[[email protected] zuoye]# vim 4.6.sh
#!/bin/bash
ping -c2 $1 &>/dev/null
if [ $? -eq 0 ];then
echo "this ip is up"
else
echo "this ip is down"
fi
7、 Alarm script , Requirements are as follows :
The remaining space in the root partition is less than 20%
Memory used space is greater than 80%
To the user alice Send alarm email
coordination crond Every time 5 Check every minute
[[email protected] zuoye]# vim 4.7.1.sh
#!/bin/bash
sy=`df -h | grep -w / |awk {'print $5'}|tr -d %`
memory_user=`free -m|grep Mem|awk {'print $3'}`
memory_total=`free -m|grep Mem|awk {'print $2'}`
memory=`echo $memory_user*100/$memory_total|bc`
if [ "$user -gt 80" -o "$memory -gt 80" ];then
echo "your / use $sy%, your mem use $memory%" |mail -s "warning" root
fi
8、 Determine whether the user input is a number , If it is a number, judge whether the number is greater than 10;
[[email protected] zuoye]# vim 4.8.sh
#!/bin/bash
read -p "please input anumber :" num
expr 1 + $num
if [ $? -eq 0 ];then
if [ $num -gt 10 ];then
echo "Is nmuber and the number more than 10"
else
echo "Is number but the number less than 10"
fi
else
echo Is not number
fi
9、 Calculate the sum of any two integers entered by the user 、 Bad 、 The product of 、 merchant 、 remainder ,
Judge whether the parameters entered by the user are two , If not , Prompt usage ;
Judge whether the user input is an integer , If not , Give a prompt to terminate the operation .
#!/bin/bash
[ $# -ne 2 ] && {
echo "usage: $0 num1 num2"
exit 1
}
expr $1 + $2 + 10 &> /dev/null
if [ $? -ne 0 ]
then
echo "you must input two number"
exit 2
fi
echo "a+b=$(($1+$2))"
echo "a-b=$(($1-$2))"
echo "a*b=$(($1*$2))"
echo "a/b=$(($1/$2))"
边栏推荐
- mysql主从复制与读写分离
- Learn NLP with Transformer (Chapter 8)
- Redis sentry, high availability executor
- Flask framework -- flask caching
- HCIA experiment (10) nat
- LVS load balancing lvs-dr builds Web Clusters and LVS combines with kept to build highly available Web Clusters
- 【flask高级】从源码深入理解flask的应用上下文和请求上下文
- HCIP(11)
- Learn NLP with Transformer (Chapter 4)
- MySQL | GROUP_ The concat function concatenates the values of a column with commas
猜你喜欢

Some usages of beautifulsoup

C# Newtonsoft. Jason advanced usage

Flask framework - session and cookies

Esp32c3 based on the example tutorial of esp32 Rainmaker development under Arduino framework

Flask framework - flask WTF form: data validation, CSRF protection

Ue4.26 source code version black screen problem of client operation when learning Wan independent server
Learning Weekly - total issue 63 - an open source local code snippet management tool

HCIP (01)

Learn NLP with Transformer (Chapter 1)
Learn NLP with Transformer (Chapter 3)
随机推荐
The B2B2C multi merchant system has rich functions and is very easy to open!!!
MLX90640 红外热成像仪测温模块开发笔记(五)
NowCoderTOP7-11——持续更新ing
UE4.26源码版学习广域网独立服务器时遇到的客户端运行黑屏问题
What is MySQL transaction
Learn NLP with Transformer (Chapter 1)
HCIP(13)
Software Testing Technology: cross platform mobile UI automated testing (Part 1)
shell- 第七章练习
The University of Gottingen proposed clipseg: a model that can perform three segmentation tasks simultaneously using text and image prompts
Esp32c3 based on the example tutorial of esp32 Rainmaker development under Arduino framework
【高并发】通过源码深度分析线程池中Worker线程的执行流程
[servlet] request parsing
Learn NLP with Transformer (Chapter 7)
Learning Weekly - total issue 63 - an open source local code snippet management tool
A troubleshooting record of DirectShow playback problems
web移动端:touchmove实现局部滚动
Mlx90640 infrared thermal imager temperature measurement module development notes (V)
Learn NLP with Transformer (Chapter 3)
30000 word express Servlet