0
点赞
收藏
分享

微信扫一扫

SHELL 传参 控制进程 启停查看状态

​​date.sh​​

#!/bin/bash

for((;;))
do
date
done

​​test.sh​​

#!/bin/bash

case $1 in

"start"){
echo "==== 1. 启动 date.sh ===="
nohup sh date.sh > test.log 2>&1 &
tail -f test.log
};;

"stop"){
echo "==== 2. 停止 date.sh ===="
ps -ef|grep -v "grep"|grep "date.sh"|awk '{print $2}'|xargs kill -9
};;

"status"){
echo "==== 3. 查看 date.sh 进程状态 ===="
ps -ef|grep -v "grep"|grep "date.sh"
};;

esac

​​脚本使用​​

启动

sh test.sh start

停止

sh test.sh stop

查看状态

sh test.sh status


举报

相关推荐

0 条评论