当前位置:网站首页>Shell第二天作业
Shell第二天作业
2022-07-26 08:12:00 【三俩两】
1、ping主机测试,查看主机是否存活;
mkdir -p /shells/test
cd /shells/test/
vim 1.sh
#!/bin/bash
if ping -c2 192.168.227.130 &>/dev/null
then
echo "192.168.227.130 is reachable"
else
echo "192.168.227.130 is not reachable"
fi
bash 1.sh
2、判断一个用户是否存在;
vim 2.sh
#!/bin/bash
read -p "input your user:" user
id $name &>/dev/null
if [ $? -eq 0 ]
then
echo "$user exitence"
else
echo "$user exitence"
fi
bash 2.sh
3、判断当前内核主版本是否为3,且次版本是否大于10;
vim 3.sh
#!/bin/bash
main = uname -r | cut -d '.' -f 1
inmain = uname -r | cut -d '.' -f 2
if [ "$main" -eq 3 ] && [ "$inmain" -ge 10 ]
then
echo "main version is "$main" inmain version is "$inmain""
else
echo "main version is not 3 inmain version is more than 10"
fi
~
bash 3.sh
4、判断vsftpd软件包是否安装,如果没有则自动安装;
vim 4.sh
#!/bin/bash
rpm -qa | grep vsftpd >&/dev/null
if [ $? -eq 0 ]
then
echo" Installed "
else
yum isntall -y vsftpd
fi
bash 4.sh
5、判断httpd是否运行;
vim 5.sh
#!/bin/bash
status="`ps -ef | grep httpd | wc -l`"
if [ $status -ge 1 ]
then
echo "httpd is running"
else
echo "httpd is not running"
fi
bash 5.sh
6、判断指定的主机是否能ping通,必须使用$1变量;
vim 6.sh
#!/bin/bash
ping -c2 192.168.227.130 &>/dev/null
if [ "$?" -eq 0 ]
then
echo "192.168.227.130 is reachable"
else
echo "192.168.227.130 is not reachable"
fi
bash 6.sh
7、报警脚本,要求如下:
根分区剩余空间小于20%
内存已用空间大于80%
向用户alice发送告警邮件
配合crond每5分钟检查一次
[[email protected] ~]# echo “邮件正文” | mail -s “邮件主题” alice
vim 7.sh
#!/bin/bash
root_total=`free -m | tr -s " " | cut -d" " -f2 | head -2 | tail -1`
root_used=`free -m | tr -s " " | cut -d" " -f3 | head -2 | tail -1`
mem_used=`df -hP | tr -s " " | cut -d" " -f5 | head -2 | tail -1 | cut -d"%" -f1`
root=$[$root_used / $root_total]
if [ $root -gt 80 ]
then
echo "gen less than20%" | mail -s "报警信息" alice
elif [ $mem_used -gt 80 ]
then
echo "member is more than 80%" | mail -s "报警信息" alice
else
echo "is usuall"
fi
bash 7.sh
8、判断用户输入的是否是数字,如果是数字判断该数字是否大于10
vim 9.sh
#!/bin/bash
read -p "please input number:" num
expr $num + 1 >&/dev/null
if [ $? -eq 0 ]
then
echo "this is a number"
else
echo "this is not a number"
fi
bash 9.sh
9、计算用户输入的任意两个整数的和、差、乘积、商、余数,
判断用户输入的参数是否是两个,如果不是,提示用法;
判断用户输入的是否是整数,如果不是,则给出提示终止运行。
a=$1
b=$2
if [ $# -eq 2 ]
then
if [[ "$a" =~ ^[0-9]*$ && "$b" =~ ^[0-9]*$ ]]
then
echo "a、b is a number"
echo a+b=$((a+b))
echo a-b=$((a-b))
echo a*b=$((a*b))
echo a/b=$((a/b))
echo a%b=$((a%b))
else
echo "a、b is not a number"
exit 0
fi
else
echo "this is not two number"
exit 0
fi
边栏推荐
- 2022/7/11 exam summary
- 99 multiplication table and inverted triangle 99 multiplication table
- Burp Suite-第二章 Burp Suite代理和浏览器设置
- Utils connection pool
- Burp suite Chapter 4 advanced options for SSL and proxy
- Use js to count the number of occurrences of each string in the string array, and format it into an object array.
- Let's talk about the three core issues of concurrent programming.
- Summary of distributed related interview questions
- utils 连接池
- Stack simulation queue
猜你喜欢

2022-07-08 group 5 Gu Xiangquan's learning notes day01

宇宙第一 IDE 霸主,换人了。。。

Strtus2历史漏洞复现

Burp Suite - Chapter 1 burp suite installation and environment configuration
分享高压超低噪声LDO测试结果(High Voltage Ultra-low Noise LDO)

FTP service

美女裸聊一时爽,裸聊结束火葬场!

SPSS uses kmeans, two-stage clustering and RFM model to study the behavior law data of borrowers and lenders in P2P network finance

Establishment and use of openstack cloud platform

数组的介绍--Array
随机推荐
Common Oracle functions
The difference between overloading and rewriting
The most complete network: detailed explanation of six constraints of MySQL
The idea of stack simulating queue
BGP --- 边界网关协议
分享高压超低噪声LDO测试结果(High Voltage Ultra-low Noise LDO)
Excel file reading and writing (creation and parsing)
[June 29, 2022] examination summary
一点一点理解微服务
Enterprise private network construction and operation and maintenance
2022-07-09 group 5 Gu Xiangquan's learning notes day02
An empirical study on urban unemployment in Guangxi (Macroeconomics)
FTP service
99 multiplication table and inverted triangle 99 multiplication table
Add traceid to the project log
Idea settings set shortcut keys to convert English letters to case in strings
The difference between equals() and = =
Template summary
Reading and writing properties file
Understand microservices bit by bit