shell 脚本实现退点输出

1、elasticsearch启动脚本

 1 #!/bin/bash
 2 export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64
 3 export JAVA_BIN=/usr/java/jdk1.8.0_201-amd64/bin
 4 export PATH=$JAVA_BIN:$PATH
 5 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
 6 export JAVA_HOME JAVA_BIN PATH CLASSPATH
 7 . /etc/init.d/functions 
 8 function echo_point()
 9 {
10   min=1
11   max=2
12   while [ $min -le $max ]
13   do
14   for((i=0;i<4;i++))
15      do
16         printf "."
17         sleep 1
18      done
19  min=`expr $min + 1`  
20  done
21  printf "   "
22 }
23 
24 
25 case $1 in
26 start)
27 
28     su - elasticsearch<<!
29     cd /opt/kidx/deploy/elasticsearch && ./bin/elasticsearch -d
30 exit
31 !
32     echo_point
33     action  "elasticsearch startup" /bin/true
34     ;;  
35 stop)
36     es_pid=`ps aux|grep elasticsearch | grep -v "grep elasticsearch" | grep -v "\-\-color" | awk '{print $2}'`
37     for i in $es_pid;
38     do
39         kill -9 $i
40     done
41     echo_point 
42     action "elasticsearch stop" /bin/true
43     ;;  
44 restart)
45     es_pid=`ps aux|grep elasticsearch | grep -v "grep elasticsearch" | grep -v "\-\-color" | awk '{print $2}'`
46     for i in $es_pid;
47     do
48         kill -9 $i
49     done
50     echo_point 
51     action "elasticsearch stop" /bin/true
52     
53     su - elasticsearch<<!
54     cd /opt/kidx/deploy/elasticsearch && ./bin/elasticsearch -d
55 exit
56 !
57     echo_point 
58     action "elasticsearch startup" /bin/true
59     ;;
60   
61 status)
62     es_pid=`ps aux|grep elasticsearch | grep -v "grep elasticsearch" | grep -v "\-\-color"| awk '{print $2}'|wc -l`
63     if [ $es_pid -eq 0 ];then
64          action "elasticsearch is down...." /bin/true
65     else
66          action "elasticsearch is running..." /bin/true
67     fi
68     ;; 
69 *)
70     echo "start|stop|restart"
71     ;;  
72 esac

 

2、循环输出退格省略号

 1 #!/bin/sh
 2 function start_pro()
 3 {
 4   min=1
 5   max=2
 6   while [ $min -le $max ]
 7   do
 8   for((i=0;i<6;i++))
 9   do
10         printf "."
11         #printf " "
12         #printf "\b"
13         sleep 1
14   done
15   tab
16  min=`expr $min + 1`  #i++
17  #printf $min
18  done
19  printf "\n"
20 }
21 
22 
23 function tab()
24 {
25   for((i=0;i<6;i++))
26   do
27         printf "\b"  #退回
28         sleep 1
29   done
30 }
31 
32 
33 
34 
35 case $1 in
36         start)
37         start_pro
38         ;;
39         stop)
40         echo "stop....."
41         ;;
42 esac 

 

posted @ 2019-06-20 17:19  kindnull  阅读(283)  评论(0编辑  收藏  举报