知识点包括:case语句,cat多行输入,break和exit的区别,wget断点续传,while中断条件写法,函数的使用方法
#!/bin/bash
echo "\n1. 本机容器情况如下"
docker ps echo "\n2. apache文件包有: "
ls | grep apache echo "\n3. webapps文件包情况:"
ls | grep webapp cat << END 你可以做的操作如下
. 移走apache
. 删除webapps
. 外部没web服务,不做任何操作
END
read -p "请做出你的选择: " num # 1. case选择函数
choose() {
case $num in
)
echo "移走apache"
mkdir -p school_deploy/tomcat/axinfu/bak/201807_update/apache
mv apache* school_deploy/tomcat/axinfu/bak/201807_update/apache/
;;
) echo "删除webapps"
rm -rf webapps/
;;
) echo "容器外部已没web文件,继续执行下面的命令"
break #这里不能用exit,否则直接退出脚本
;;
esac
} # 2. 监控功能函数
function(){
# -c:断点续传,-t:重试次数 -T:超时时间
wget -t -T -c http://47.52.136.86:8088/xuexiaodaima.csv read -p "please input school name: " name
x=$(cat xuexiaodaima22.csv | grep $name)
code=$(echo "$x" | cut -d "," -f )
echo $code
sleep mkdir zabbix && cd zabbix
wget -t https://wars.oss-cn-hangzhou.aliyuncs.com/zabbix-agent.tar.gz
tar xzf zabbix-agent.tar.gz && cd etc
read -p "please input school code: " code1
sed -i "s/haerbingtiyu/$code1/g" zabbix_agentd.conf #开启docker-compose
cd ..
docker-compose up -d
} # 3. 执行函数function()和choose()
function
eval=1
while eval
do
choose
if [ $num != "3" ];then
read -p "请做出你的选择: " num
else
echo "执行下面的命令"
$eval=-1
fi
done