linux 自定义short脚本

执行脚本


alias ppsapp='. /home/sfapp/.pps_profile jetty PPS_APP_CNSZ22_JETTY_01'




脚本语言

#!/bin/bash

createShortCmd()
{
    if [ $# -ne 3 ];
    then
       return 1;
    fi

    v_sbase=$1
    v_slog=$2
    v_slname=$3

    export jbase="${v_sbase}"
    export jserver="${jbase}/server"
    export japp="${jserver}/${jname}"
    export jwar="/app/war/${jname}"
    export jlog="${jserver}/${jname}/${v_slog}"

    if [ ${server_type} = 'jetty' ];then
        alias start="sudo ${jbase}/logs/${jname}.sh start"
        alias stop="sudo ${jbase}/logs/${jname}.sh stop"
        alias restart="sudo ${jbase}/logs/${jname}.sh restart"
    else
        alias start="${jbase}/logs/${jname}.sh start"
        alias stop="${jbase}/logs/${jname}.sh stop"
        alias restart="${jbase}/logs/${jname}.sh stop; ${jbase}/logs/${jname}.sh start"
    fi

    alias log="tail -400f ${jserver}/${jname}/${v_slog}/${v_slname}"
    alias vlog="vi -R ${jserver}/${jname}/${v_slog}/${v_slname}"
    alias mlog="more ${jserver}/${jname}/${v_slog}/${v_slname}"
    alias p="ps -ef | head -1; ps -ef | grep "${jname}" | grep java | grep -v grep"
}

main()
{

    if [ $# -ne 2 ];
    then
       return;
    fi

    #print server inforamtion
    alias jman='echo -e "server info [ server type: ${server_type} ; app name: ${server_app_name} ]\n"'
    alias helpme='echo -e "\nshort env: jbase,jserver,jname,japp,jwar,jlog \nshort command: jman,start,stop,restart,log,vlog,mlog,p\n"'
    alias ..="cd .."
    export jname="${server_app_name}"

    v_server_base=''
    v_server_log=''
    v_server_log_name=''

    case "$server_type" in
         jboss)
             v_server_base="/app/jboss/jboss-as"
             v_server_log="log"
             v_server_log_name='server.log'
             ;;
          jetty)
             v_server_base="/app/jetty"
             v_server_log="logs"
             v_server_log_name="novatar_${curdate}_audit.0.log"
             ;;
             *)
    esac

    createShortCmd ${v_server_base} ${v_server_log} ${v_server_log_name}
}

server_type=$1
server_app_name=$2

alias ..='cd ..'
curdate=`date '+%Y%m%d'`

#execute main function
main $@


你可能感兴趣的:(LINUX)