1、ping主机测试,查看主机是否存活;
脚本如下所示:
read -p "please input your hostname:" hostname
ping -c2 $hostname &> /dev/null
if [ $? = 0 ]
then
echo "host $hostname is ok"
else
echo "host $hostname is fail"
fi
结果如下所示:
[root@rhcsa ~]# ./ping.sh
please input your hostname:www.baidu.com
host www.baidu.com is ok
[root@rhcsa ~]# ./ping.sh
please input your hostname:192.168.188.200
host 192.168.188.200 is fail
[root@rhcsa ~]#
2、判断一个用户是否存在;
#!/bin/bash
##############################################################
# File Name: 2.sh
# Version: V1.0
# Author: xx
# Email: xx@163.com
# Organization: http://www.xx.com/xx/
# Created Time : 2022-07-16 16:44:24
# Description:
##############################################################
read -p "please input username:" username
grep "$username" /etc/passwd &> /dev/null
if [ $? -eq 0 ];then
echo "$username is already exist"
else
echo "$username is not exist"
fi
3、判断当前内核主版本是否为3,且次版本是否大于10;
#!/bin/bash
##############################################################
# File Name: ke