Skip to content

Instantly share code, notes, and snippets.

@zombie110year
Last active February 17, 2019 05:52
Show Gist options
  • Select an option

  • Save zombie110year/18d2180b5afea1a0ad224145108a5c77 to your computer and use it in GitHub Desktop.

Select an option

Save zombie110year/18d2180b5afea1a0ad224145108a5c77 to your computer and use it in GitHub Desktop.
简单的 bash 脚本, 用于启动与终止某后台程序
#! /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