{"id":54,"date":"2025-01-03T10:35:25","date_gmt":"2025-01-03T02:35:25","guid":{"rendered":"http:\/\/www.handytoo.com\/?p=54"},"modified":"2025-01-03T10:35:25","modified_gmt":"2025-01-03T02:35:25","slug":"bash-shell-%e6%9c%8d%e5%8a%a1%e9%80%9a%e7%94%a8%e6%8e%a7%e5%88%b6%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/www.handytoo.com\/?p=54","title":{"rendered":"Bash shell \u670d\u52a1\u901a\u7528\u63a7\u5236\u811a\u672c"},"content":{"rendered":"\n<p>\u811a\u672c1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\nELF_PATH=\"\/onlineapp\/cut_server\/server.py\"\nEXEC_CMD=\"\/usr\/bin\/python $ELF_PATH\"\n#function\nstart(){\n\t#test have started\n\tPRO_PID=`ps -ef | grep -v grep | grep $ELF_PATH | awk '{print $2}'`\n\tif &#91; \"$PRO_PID\" != \"\" ]; then\n\t\techo \"$ELF_PATH have started!\"\n\t\texit 1\n\tfi\n\t#start\n\tnohup $EXEC_CMD &amp;\n}\n\nstop(){\n\techo $ELF_PATH\n\tPRO_PID=`ps -ef | grep -v grep | grep $ELF_PATH | awk '{print $2}'`\n\techo $PRO_PID\n\tif &#91; \"$PRO_PID\" != \"\" ]; then\n\t\tfor curpid in $PRO_PID\n\t\tdo\n\t\t\techo $curpid\n\t\t\tkill -9 $curpid\n\t\tdone\n\t\techo \"$ELF_PATH stoped!\"\n\telse\n\t\techo \"PID Not Found !\"\n\tfi\n}\n\ncase $1 in\n\t\"start\")\n\t\tstart\n\t;;\n\t\"stop\")\n\t\tstop\n\t;;\n\t\"restart\")\n            stop\n            echo \"3\"\n            sleep 1\n            echo \"2\"\n            sleep 1\n            echo \"1\"\n            sleep 1\n            start\n\t;; \n\t*)\n\t\techo \".\/shell param\"\n\t\techo \"    start         start Server\"\n\t\techo \"    stop          stop Server\"\n\t;;\nesac\n\nps -A -opid,stime,etime,args | grep $ELF_PATH | grep -v grep\n\nexit 0<\/code><\/pre>\n\n\n\n<p>\u811a\u672c2<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\nES_HOME=\"\/developenv\/elk\/elasticsearch-7.11.1\"\nAPP_NAME=\"elasticsearch\"\necho \"\u5f00\u59cb\u6267\u884c $APP_NAME \u63a7\u5236\u811a\u672c\"\n# \u4f7f\u7528\u65b9\u5f0f\nusage() {\n\techo \"case:sh run.sh &#91;start | stop | restart | status]\"\n\techo \"\u8bf7\u7c7b\u4f3c\u8fd9\u6837\u6267\u884c .\/*.sh start or .\/*sh restart\"\n\texit 1\n}\n\n# \u5224\u65ad\u5f53\u524d\u670d\u52a1\u662f\u5426\u5df2\u7ecf\u542f\u52a8\u7684\u51fd\u6570\nis_exist() {\n\techo \"\u6267\u884c is_exist\u65b9\u6cd5\"\n\tpid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}'`\n\tif &#91; -z \"${pid}\" ]; then\n\t\techo \"pid is null.\"\n\t\treturn 1\n\telse\n\t\techo \"pid &lt;> null\"\n\t\treturn 0\n\tfi\n}\n# \u542f\u52a8\nstart() {\n\tis_exist\n\tif &#91; $? -eq 0 ]; then\n\t\techo \"${APP_NAME} running. pid=${pid}\"\n\telse\n\t    su elk -c \"sh ${ES_HOME}\/bin\/elasticsearch -d -p ${ES_HOME}\/pid\"\n\t\techo \"${APP_NAME} started\"\n\tfi\n}\n# \u505c\u6b62\nstop() {\n\techo \"\u6267\u884cstop\u65b9\u6cd5\"\n\tis_exist\n\tif &#91; $? -eq 0 ]; then\n\t\tkill `cat ${ES_HOME}\/pid`\n\t\techo \"${pid} stop\"\n\telse\n\t\techo \"${APP_NAME} not running\"\n\tfi\n}\n#\u91cd\u542f\nrestart() {\n\tstop\n\tstart\n}\ncase \"$1\" in \n\t\"start\")\n\t\tstart\n\t\t;;\n\t\"stop\")\n\t\tstop\n\t\t;;\n\t\"restart\")\n\t\trestart\n\t\t;;\n\t*)\n\t\tusage\n\t\t;;\nesac<\/code><\/pre>\n\n\n\n<p>\u811a\u672c3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\nBEATHOME=\"\/developenv\/elk\/filebeat-7.11.1\"\nAPP_NAME=\"filebeat\"\nAGENT=\"$BEATHOME\/filebeat\"\nLOGFILE=\"$BEATHOME\/filebeat.log\"\nARGS=\"-e -c $BEATHOME\/filebeat.yml\"\n\nstart() {\n    pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}'`\n    if &#91; -z \"${pid}\" ];then\n        echo \"Starting filebeat: \"\n        nohup $AGENT $ARGS > $LOGFILE &amp;\n        if &#91; $? == '0' ];then\n            echo \"start filebeat ok\"\n        else\n            echo \"start filebeat failed\"\n        fi\n    else\n        echo \"filebeat is still running!\"\n        exit\n    fi\n}\n\nstop() {\n    echo -n $\"Stopping filebeat: \"\n    pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}'`\n    if &#91; -z \"${pid}\" ];then\n\techo \"filebeat is not running\"\n    else\n        kill $pid\n\techo \"stop filebeat ok\"\n    fi\n}\n\nrestart() {\n    stop\n    start\n}\n\nstatus(){\n    pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}'`\n    if &#91; -z \"${pid}\" ];then\n        echo \"filebeat is not running\"\n    else\n        echo \"filebeat is running\"\n    fi\n}\ncase \"$1\" in\n    start)\n        start\n    ;;\n    stop)\n        stop\n    ;;\n    restart)\n        restart\n    ;;\n    status)\n        status\n    ;;\n    *)\n        echo $\"Usage: $0 {start|stop|restart|status}\"\n        exit 1\nesac<\/code><\/pre>\n\n\n\n<p>\u811a\u672c4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\nSERVER_HOME=\"\/developenv\/elk\/kibana-7.11.1\"\nLOG_HOME=$SERVER_HOME\/logs\nBIN_HOME=$SERVER_HOME\/bin\n\nSTART_SHELL=$BIN_HOME\/kibana\nPIDFILE=$BIN_HOME\/server.pid\nCONSOLE=$LOG_HOME\/kibana-console_`date '+%Y-%m-%d'`.log\ntest -d $LOG_HOME || mkdir -p $LOG_HOME\n\nstart()\n{\n        echo \"staring ...\"\n\tnohup $START_SHELL >$CONSOLE 2>&amp;1  &amp;\n\techo $! > $PIDFILE\n}\n\nstop()\n{\nif &#91; -f \"$PIDFILE\" ] ; then\n    echo \"kibana stoping..\"    \n    kill `cat $PIDFILE`\n    sleep 1\n    rm -rf $PIDFILE\n    echo \"stop kibana success\"\n  else\n    echo \"kibana is not running\"\n    exit 0;\n  fi;\n}\n\nstatus()\n{\n    if &#91; -f \"$PIDFILE\" ] ; then\n       pid=`cat $PIDFILE`\n       if &#91;&#91; pid -gt 0 ]]\n       then\n           echo \"&#91;$(date '+%Y-%m-%d %T')] kibana is running.( pid:$pid )\"\n       else\n            echo \"&#91;$(date '+%Y-%m-%d %T')] kibana is not running\"\n       fi\n    else \n         echo \"kibana is not running\"\n    fi\n}\n\nrestart()\n{\n   stop\n   start\n}\n\ncase \"$1\" in\n    start)\n        start\n        ;;\n    stop)\n        stop\n        ;;\n    status)\n         status\n        ;;\n    restart)\n        restart\n        ;;\n    *)\n     echo \"Usage: bash .\/server.sh {start|status|stop|restart}\"\n        exit 1\n        ;;\nesac\nexit 0<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u811a\u672c1 \u811a\u672c2 \u811a\u672c3 \u811a\u672c4<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[23],"class_list":["post-54","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.handytoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=54"}],"version-history":[{"count":1,"href":"https:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":55,"href":"https:\/\/www.handytoo.com\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions\/55"}],"wp:attachment":[{"href":"https:\/\/www.handytoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.handytoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.handytoo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}