1.check_host.sh用此脚本检测10台与您当前主机直连主机是否网络通常,如果网络通常请显示主机的ip列表.
2.脚本练习:
check_file.sh
please input filename: file
file is not exist
file is file
file is direcory
此脚本会一直询问直到用户输入exit为止
3.脚本练习
user_ctrl.sh
一、运行脚本时,会一直输入提示语;please input action [add|del|exit]:
二、如果输入add.则需有提示语 please input username:
输入用户名,:1:如果用户本身存在:则显示 所输的username is exist
2: 如果输入的用户不存在,则建立用户,并显示提示语:please input password
输入密码,建立用户完成。
三、如果输入del:1:如果用户存在,删除用户,2:如果用户不存在,则显示用户不存在
四、直到输入exit,才会退出。
[ "$USER" = "root" ]||{
echo please run $0 with super user
exit
}
while true
do
read -p "please input action [add|del|exit]:" action
case $action in
add|ADD|Add )
read -p " please input username:" username
id $username &> /dev/null
if [ "$?" = "0" ] ##id命令有结果
then
echo $username is exist
else
useradd $username &>/dev/null
read -p "please input password :" password
echo $password | passwd --stdin $username
echo passwd is created
fi
;;
del|DEL|Del)
read -p "please input username:" username
id $username &>/dev/null
if [ "$?" = "0" ]
then
userdel -r $username
echo $username is deleted
else
echo $username is not exist
fi
;;
exit)
echo bye
exit
;;
esac
done
;
4.脚本练习
system_watch.sh disk memory upload (每秒显示)
disk 监控磁盘使用情况
memory 监控内存使用情况
upload 监控启动负载