cmd="/home/scue/bin/ipclient $ipclient"
exist=$(ps aux | grep -v 'grep' | grep "$cmd" | awk '{print $2}')
kill_process(){
kill -9 $exist
}
if [[ "$1" != "" ]] ; then
kill_process
else
if [[ "$exist" != "" ]]; then
kill_process
fi
nohup $cmd >/dev/null 2>&1 &
fi
效果:执行$cmd的内容,并且不会重复执行(自动结束之前的程序)
关闭:./test <any_args>,只要有传入参数,就结束这个$cmd,默认不传入时,就执行$cmd。