当前位置:网站首页>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))"
边栏推荐
- LVS load balancing lvs-dr builds Web Clusters and LVS combines with kept to build highly available Web Clusters
- 【高并发】通过源码深度分析线程池中Worker线程的执行流程
- Signal integrity (SI) power integrity (PI) learning notes (XXXIV) 100 rules of thumb for estimating signal integrity effects
- ArcMap无法启动解决方法
- tensorflow 调用多块GPU的一些错误
- 苹果美国宣布符合销售免税假期的各州产品清单细节
- mysql高级语句(一)(总有一个人的出现,让你的生活不再继续糟糕)
- Learn NLP with Transformer (Chapter 2)
- shell- 第七章练习
- [flask advanced] deeply understand the application context and request context of flask from the source code
猜你喜欢
Learning Weekly - total issue 63 - an open source local code snippet management tool

AI system frontier dynamics issue 43: ONEFLOW V0.8.0 officially released; GPU finds human brain connections; AI doctoral online crowdfunding research topic

NowCoderTOP1-6——持续更新ing
苹果美国宣布符合销售免税假期的各州产品清单细节

玩游戏想记录一下自己超神的瞬间?那么就来看一下如何使用Unity截图吧

STM32CubeMX学习记录--安装配置与使用
Learn NLP with Transformer (Chapter 2)

Learn PHP -- phpstudy tips mysqld Exe: Error While Setting Value ‘NO_ ENGINE_ Solution of substitution error

游戏背包系统,“Inventory Pro插件”,研究学习-----妈妈再也不用担心我不会做背包了(Unity3D)

SQL语言(二)
随机推荐
shell- 第七章练习
【flask高级】结合源码详解flask的运行机制(出入栈)
学习路之PHP--Phpstudy 提示 Mysqld.Exe: Error While Setting Value ‘NO_ENGINE_SUBSTITUTION 错误的解决办法
Digital twin everything can be seen | connecting the real world and digital space
LVS负载均衡之LVS-NAT搭建Web群集
数据库设计-简化字典表[通俗易懂]
Smart cloud IOT platform STM32 esp8266-01s simple wireless light control
Multiply Floyd "suggestions collection"
Reinforcement learning (III)
SQL语言(二)
HCIP(12)
机智云物联网平台 STM32 ESP8266-01S 简单无线控灯
JS convert pseudo array to array
HCIP (01)
SQL语言(六)
[cloud enjoys freshness] community weekly · Vol 72 - the first opening ceremony of the 2022 Huawei developer competition in China was launched; Huawei cloud koomessage is in hot public beta
shell-第五章作业
The University of Gottingen proposed clipseg: a model that can perform three segmentation tasks simultaneously using text and image prompts
[flask advanced] deeply understand the application context and request context of flask from the source code
HDD Hangzhou station full experience