Last active
February 17, 2019 05:52
-
-
Save zombie110year/18d2180b5afea1a0ad224145108a5c77 to your computer and use it in GitHub Desktop.
简单的 bash 脚本, 用于启动与终止某后台程序
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/bash | |
| # path of program | |
| BIN= | |
| # command line args for $BIN | |
| OPTS= | |
| # description | |
| DESCRIPTION= | |
| cmd=$1 | |
| case $cmd in | |
| "start") | |
| nohup $BIN "$OPTS" >> /dev/null 2>&1 & | |
| pid=$(ps -ef | grep $BIN | grep -v grep | awk '{print $2}') | |
| printf "start as pid=$pid\n" | |
| ;; | |
| "stop") | |
| pid=$(ps -ef | grep $BIN | grep -v grep | awk '{print $2}') | |
| kill $pid | |
| printf "kill $pid\n" | |
| ;; | |
| *) | |
| printf "$DESCRIPTION\n" | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment