Case syntax and use + call function and output log in real time

Test case

case "$1" in
  check)
        if [ -f "$LOGDIR/info_$(date +%F).log" ] 
        then
          env_check & tail -f $LOGDIR/info_$(date +%F).log
        else
          touch $LOGDIR/info_$(date +%F).log
          env_check & tail -f $LOGDIR/info_$(date +%F).log
        fi 
        ;;
  config) 
        if [ -f "$LOGDIR/info_$(date +%F).log" ] 
        then
          env_config & tail -f $LOGDIR/info_$(date +%F).log
        else
          touch $LOGDIR/info_$(date +%F).log
          env_config & tail -f $LOGDIR/info_$(date +%F).log
        fi
        ;;
  docker)
        if [ -f "$LOGDIR/info_$(date +%F).log" ] 
        then
          docker_install & tail -f $LOGDIR/info_$(date +%F).log  
        else
          touch $LOGDIR/info_$(date +%F).log
          docker_install & tail -f $LOGDIR/info_$(date +%F).log
        fi
        ;;
  kube)
        if [ -f "$LOGDIR/info_$(date +%F).log" ] 
        then
          assembly_install & tail -f $LOGDIR/info_$(date +%F).log
        else
          touch $LOGDIR/info_$(date +%F).log
          assembly_install & tail -f $LOGDIR/info_$(date +%F).log
        fi
        ;;
  init)
        if [ -f "$LOGDIR/info_$(date +%F).log" ]
        then
          k8s_init & tail -f $LOGDIR/info_$(date +%F).log
        else
          touch $LOGDIR/info_$(date +%F).log
          k8s_init & tail -f $LOGDIR/info_$(date +%F).log
        fi
     ;;
 install)
        if [ -f "$LOGDIR/info_$(date +%F).log" ] 
        then
          env_check && docker_install && env_config && env_check && assembly_install && k8s_init & tail -f $LOGDIR/info_$(date +%F).log
        else
          touch $LOGDIR/info_$(date +%F).log
          env_check && docker_install && env_config && env_check && assembly_install && k8s_init tail -f $LOGDIR/info_$(date +%F).log
        fi
     ;;
  help)
     echo "check: check the envirnment ,use it firstly!"
     echo "docker: install the docker,use it Secondly!"
     echo "config: config the args,use it thirdly!"
     echo "kube and init: install k8s master,use it lastly!"
     echo "install : It's a way to quick install what you need!"
             ;;
  *)
        echo "Usage: please use k8s_master {check|config|docker|kube|init|help|install}"  ;;
esac
exit 0

Guess you like

Origin blog.csdn.net/qq_38774492/article/details/108101371