#!/bin/bash
echo "##########################################"
echo "# 192.168.20.12 | oauth-server oauth-app #"
echo "# 192.168.20.12 | im-server im-app #"
echo "##########################################"
DATA=/data/prog/project
IP1=192.168.20.12
IP2=192.168.20.13
PS3="删除的主机日志选择: "
while true; do
select logs_version in 192.168.20.12 192.168.20.13 quit; do
case $logs_version in
192.168.20.12)
for i in oauth-server oauth-app ; do
chdir=$DATA/$i/logs
ansible $IP1 -m shell -a ">$DATA/$i/logs/$i-console.log"
done
if [ -s "$DATA/$i/logs/$i-console.log" ]; then
echo "========日志未清空========"
else
echo "========日志已清空========"
sleep 1
echo "======请继续您的选择======"
fi
;;
192.168.20.13)
for i in im-app im-server ; do
chdir=$DATA/$i/logs
ansible $IP1 -m shell -a " > $DATA/$i/logs/$i-console.log"
ansible $IP2 -m shell -a " > $DATA/$i/logs/$i-console.log"
done
;;
quit)
exit 2;
;;
*)
echo "请正常输入您的选项!"
esac
done
done
或者另一种自己打印菜单选项
#!/bin/bash
echo "##########################################"
echo "# 192.168.20.12 | oauth-server oauth-app #"
echo "# 192.168.20.12 | im-server im-app #"
echo "##########################################"
function menu() { #menu菜单函数
cat <<bqh
1.192.168.20.12
2.192.168.20.13
3.quit
bqh
}
menu
#function usage() { #usage交互式函数提示
#echo -e "${SHAN}您的主机日志选择:{1|2|3}$RES"
#}
read -p "删除的主机日志选择:" num
expr $num + 1 &>/dev/null #判断是否为整数
if [ $? -ne 0 ];then #判断执行结果是否为0
exit 0
fi
DATA=/data/prog/project
IP1=192.168.20.12
IP2=192.168.20.13
case $num in
1)
for i in oauth-server oauth-app ; do
chdir=$DATA/$i/logs
ansible $IP1 -m shell -a ">$DATA/$i/logs/$i-console.log"
done
if [ -s "$DATA/$i/logs/$i-console.log" ]; then
echo "========日志未清空========"
else
echo "========日志已清空========"
sleep 1
fi
# usage
;;
2)
for i in im-app im-server ; do
chdir=$DATA/$i/logs
ansible $IP1 -m shell -a " > $DATA/$i/logs/$i-console.log"
ansible $IP2 -m shell -a " > $DATA/$i/logs/$i-console.log"
done
;;
3)
exit 1
;;
*)
echo "请正常输入您的选项!"
exit 2
esac
#############脚本有缺陷