简单的shell脚本-程序启停

启动脚本

#!/bin/bash
bash -c "echo $$ > ${PWD}/processId"
/path/to/script.sh

脚本的用途:保存当前进程号到文件processId,启动脚本

后台运行

#!/bin/bash
nohup ./start.sh > /path/to/log &

脚本用途:后台运行 start.sh ,并将日志重定向

停止-清理

#!/usr/bin/bash

awk '{NF=1}1' processId | xargs kill -9
rm logs.log

脚本用途:停止进程 processId  ,并删除日志文件

补充

awk在脚本编写中有非常用途。

本人还在学习编写bash脚本中。

学习资料:网站

原文地址:https://www.cnblogs.com/peng18/p/14248025.html