1.自动安装http 并修改端口
#!/bin/bash
read -p “需要修改端口为多少:” 1
yum install -y httpd &> /dev/null
sed -i "/^Listen/cListen $1" /etc/httpd/conf/httpd.conf
echo -e "Port has changed!"
echo "Now ,Port is $1!"
systemctl restart httpd
2.列出uid小于2的用户信息
#!/bin/bash
awk -F: '$3 >= 0 && $3 < 2 {print $1,$3}' /etc/passwd
3.ping该网段中那些ip空闲那些工作
#!/bin/bash
#for((a=1;a<255;a++))
#for a in `seq 60`
for a in {1..60}
do
ping -c1 -w1 172.25.254.$a &> /dev/null && echo 172.25.254.$a is up || echo 172.25.254.$a is down
done
4.倒计时10s
#!/bin/bash
for ((a=10;a>0;a--))
do
echo -n " TIME $a "
echo -ne "\r \r"
sleep 1
done
5.删除westos{1…20}
#!/bin/bash
PREFIX="westos"
i=1
while [ $i -le 20 ]
do
userdel -r ${PREFIX}$i &> /dev/null
echo "123456" | passwd --stdin ${PREFIX}$i &> /dev/null
((i++))
done
打印9*9乘法表
#!/bin/bash
#1*1=1
#2*1=2 2*2=4
#3*1=3 3*2=6 3*3=9
for i in $(seq 9)
do
for j in $(seq $i)
do
echo -ne "$i*$j=$(($i*$j))\t"
done
echo -e "\n"
done
8.如果kiosk用户存在反馈 hollo kiosk
#!/bin/bash
user=kiosk
if grep $user /etc/passwd;then
echo "Hello $user"
fi
if date;then
echo "Hello date"
fi
9.如果student用户存在进入家目录
#!/bin/bash
user=student
if grep $user /etc/passwd;then
echo "The files for user $user are:"
ls -a /home/$user
else
echo "$user not exist!"
fi
10.检查输入用户是否存在
#!/bin/bash
if [ "$1" -eq "student" ];then
echo "Welcome $1"
elif [ "$1" -eq "westos" ];then
echo "Welcome $1"
elif [ "$1" -eq "kiosk" ];then
echo "Welcome $1"
elif [ "$1" -eq "linux" ];then
echo "Welcome $1"
else
echo "You are not allowed!"
fi
#!/bin/bash
case $1 in
student|kiosk|linux|westos)
echo "Welcome,$1"
;;
*)
echo "Sorry!"
;;
esac
12.监控系统,选择输出
#!/bin/bash
while true
do
echo -e "
\033[31m A 显示主机IP \033[0m
\033[32m B 显示磁盘剩余空间 \033[0m
\033[33m C 显示系统运行时间 \033[0m
\033[34m Q 退出系统 \033[0m
"
read -p "请输入你的选择:" char
case $char in
a|A)
ifconfig br0 | grep "inet " | awk '{print $2}'
;;
b|B)
df -h | awk 'NR==2{print "剩余空间大小为:"$4}'
;;
c|C)
uptime |awk '{print $3}' | awk -F, '{print $1}' | awk -F: '{print "系统已经运行了"$1"小时"$2"分钟"}'
;;
q|Q)
exit 0
;;
esac
done