28 lines
2.6 KiB
HTML
28 lines
2.6 KiB
HTML
<div class="cnblogs_code">
|
||
<pre><span style="color: #008000;">#</span><span style="color: #008000;">!/bin/bash</span><span style="color: #008000;">
|
||
#</span><span style="color: #008000;"> 文件目录</span>
|
||
fileDir=/usr/local/project/<span style="color: #000000;">back
|
||
logDir</span>=/usr/local/project/<span style="color: #000000;">logs
|
||
</span><span style="color: #008000;">#</span><span style="color: #008000;"> 设置需要检测的文件路径</span>
|
||
fileName=media-fuse-1.0.0<span style="color: #000000;">.jar
|
||
</span><span style="color: #008000;">#</span><span style="color: #008000;"> 获取当前文件最后编辑时间戳</span>
|
||
initTime=`stat -c %Y <span style="color: #800080;">$fileDir</span>/<span style="color: #800080;">$fileName</span><span style="color: #000000;">`
|
||
</span><span style="color: #008000;">#</span><span style="color: #008000;"> 循环查询文件最后编辑时间是否变化</span>
|
||
<span style="color: #0000ff;">while</span> <span style="color: #0000ff;">true</span>
|
||
<span style="color: #0000ff;">do</span><span style="color: #000000;">
|
||
changeTime</span>=`stat -c %Y <span style="color: #800080;">$fileDir</span>/<span style="color: #800080;">$fileName</span><span style="color: #000000;">`
|
||
</span><span style="color: #0000ff;">if</span> [ <span style="color: #800080;">$changeTime</span> <span style="color: #008080;">-eq</span> <span style="color: #800080;">$initTime</span><span style="color: #000000;"> ];then
|
||
echo </span>$(date +%F%n%T) <span style="color: #800080;">$fileDir</span>/<span style="color: #800080;">$fileName</span><span style="color: #000000;"> 'not change'
|
||
</span><span style="color: #0000ff;">else</span><span style="color: #000000;">
|
||
initTime</span>=<span style="color: #800080;">$changeTime</span><span style="color: #000000;">
|
||
echo </span>$(date +%F%n%T) <span style="color: #800080;">$fileDir</span>/<span style="color: #800080;">$fileName</span><span style="color: #000000;"> 'has been changed'
|
||
</span><span style="color: #008000;">#</span><span style="color: #008000;"> 杀掉进程</span>
|
||
ps -ef|grep media-fuse-1.0.0|grep -v grep|cut -c 9-15|xargs kill -9
|
||
<span style="color: #008000;">#</span><span style="color: #008000;"> 运行新的文件</span>
|
||
nohup java -jar <span style="color: #800080;">$fileDir</span>/<span style="color: #800080;">$fileName</span> > <span style="color: #800080;">$logDir</span>/media-fuse.log &<span style="color: #000000;">
|
||
fi
|
||
</span><span style="color: #008000;">#</span><span style="color: #008000;"> 检测间隔</span>
|
||
sleep 5<span style="color: #000000;">
|
||
done</span></pre>
|
||
</div>
|
||
<p>转自:https://blog.csdn.net/China_hdy/article/details/101303834</p> |