#!/bin/bash
#########################
#File name:ping.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2022-12-28 05:06:21
#Description:
#########################
var=$( ifconfig ens33 | grep inet | grep -v inet6 | tr -s ' '| cut -d ' ' -f 3 )
ping -c 4 "$var" &>/dev/null
if [ $? -eq 0 ];then
echo "ping success"
else
echo "ping failed"
fi
#!/bin/bash
#########################
#File name:userExist.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2022-12-28 05:33:33
#Description:
#########################
read -p "please input your username:" username
id $username &>/dev/null
if [ $? -eq 0 ];then
echo "$username exist"
else
echo "$username not exist"
fi
运行结果
3、判断当前内核主版本是否为3,且次版本是否大于10;
#!/bin/bash
#########################
#File name:procVersion.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2022-12-28 05:53:17
#Description:
#########################
var1=$(cat /proc/version | cut -d ' ' -f 3 | cut -d '.' -f 1)
var2=$(cat /proc/version | cut -d ' ' -f 3 | cut -d '.' -f 2)
if [ $var1 -eq 3 ];then
if [ $var2 -gt 10 ];then
echo "Kernel Major Version is 3 and Kernel minor version greater then 10"
else
echo "Kernel Major Version is 3 and kernel minor version less then 10"
fi
else
echo "Kernel Major Versin is not 3"
fi
运行结果
4、判断vsftpd软件包是否安装,如果没有则自动安装;
#!/bin/bash
#########################
#File name:package.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2022-12-28 06:44:13
#Description:
#########################
yum list installed | grep vsftpd &>/dev/null
if [ $? -ne 0 ];then
yum install -y vsftpd &>/dev/null
echo "loading ....."
echo "complete!"
else
echo "downloaded"
fi
#!/bin/bash
#########################
#File name:server.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2022-12-28 07:33:04
#Description:
#########################
var1=$( ps -ef | grep httpd | grep -v grep | wc -l )
if [ $var1 -ge 1 ];then
echo "httpd is running"
else
echo "httpd is not running"
systemctl start httpd &>/dev/null
fi
#!/bin/bash
#########################
#File name:ping_var.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2022-12-30 05:17:24
#Description:
#########################
ping -c 4 $1 &>/dev/null
if [ $? -eq 0 ];then
echo "ping success!"
else
echo "ping failed!"
fi
7、报警脚本,要求如下:
根分区剩余空间小于20%
内存已用空间大于80%
向用户root发送告警邮件
配合crond每5分钟检查一次
[root@locaklhost ~]# echo “邮件正文” | mail -s “邮件主题” root
[root@localhost practise1]# vim /etc/crontab
#!/bin/bash
#########################
#File name:mail.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2022-12-31 00:43:52
#Description:
#########################
Use_root_space=$(df -Th | grep /$ | awk '{print $6}' | cut -d '%' -f 1)
Total_mem=$(free -m | grep Mem | awk '{print $2}')
Use_mem=$(free -m | grep Mem | awk '{print $3}')
#echo $Use_root_space $Total_mem $Use_mem
Limit_mem=$((Total_mem/100))
#echo $Limit_mem
if [ $Use_root_space -ge 6 ]
then
echo "Use_root_space: $Use_root_space%" | mail -s "Root_space_warning" root
fi
if [ $Use_mem -ge $Limit_mem ]
then
echo "Use_mem: $Use_memM" | mail -s "Use_mem_warning" root
fi
if [ $Use_root_space -lt 6 -a $Use_mem -lt $Limit_mem ]
then
echo "Use_root_space: $Use_space_space% Total_mem: $Total_memM Use_mem: $Use_mem"
[root@localhost practise1]# vim /etc/crontab
*/5 * * * * root /root/test/practise1/mail.sh
8、判断用户输入的是否是数字,如果是数字判断该数字是否大于10;
#!/bin/bash
#########################
#File name:number.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2022-12-31 21:05:33
#Description:
#########################
read -p "please input a number:" num1
echo "$num1" | grep -E ^[0-9]+$
if [ $? -ne 0 ];then
echo "you must input a number"
exit 0
fi
if [ $num1 -gt 10 ]
then
echo "the number greater than 10"
else
echo "then number less than 10"
fi
9、计算用户输入的任意两个整数的和、差、乘积、商、余数,
判断用户输入的参数是否是两个,如果不是,提示用法;
判断用户输入的是否是整数,如果不是,则给出提示终止运行。
read -p "please input two integer:" num1 num2
if [ -z "$num1" -o -z "$num2" ]
then
echo "you must input two integer!"
exit 1
fi
echo "$num1$num2" | grep -E ^[0-9]+$ &>/dev/null
if [ $? -ne 0 ]
then
echo "you must input integer!"
exit 1
fi
sum=$((num1+num2))
echo "a+b=$sum"
if [ $num1 -ge $num2 ]
then
echo "a-b=$((num1-num2))"
else
echo "b-a=$((num2-num1))"
fi
echo "a*b=$((num1*num2))"
echo "a/b=$((num1/num2))"
echo "a%b=$((num1%num2))"
原文地址:https://blog.csdn.net/m0_47218990/article/details/128500601
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_20954.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。