我是 unix/linux 新手,需要一个 shell 脚本来启动未运行的程序。该程序的名称是“literaail”,它的日志位于服务器上的“/local/publish/mtc_preprint/util/Literail.log”。该程序应该打印“Starting ftp check for Get_Job1”。每 30 秒声明一次。如果没有,我需要一个 shell 脚本来启动该过程。目前我正在使用以下命令手动执行此操作:
ps -ef | grep ftp_util_mtc_pp.sh
ps -ef | grep literail ( this command lists the jar file related to the literail program)
kill "parentjobnumber" "childjobnumber"
./ftp_util_mtc_pp.sh & ( this command restarts the process ).
我有一个“ftp_util_mtc_pp.sh”文件,在这个文件中,我有以下命令:
#!/bin/bash
utildir="/local/publish/mtc_preprint/util"
cd $utildir
java -jar LiteRail_3.0.1.jar literail.properties > /dev/null 2>&1
exit
有人可以帮我编写 shell 脚本吗?谢谢。
最佳答案
此文件正在查找正在运行的 LiteRail jar,如果它正在运行,它将杀死并重新运行它,而不仅仅是运行 jar 并在给定位置添加日志。
ftp_util_mtc_pp.sh 是:
#!/bin/bash
PID= ps -ef | grep LiteRail_3
if [[ -z "$PID" ]]; then
#process is running so we kill it
Kill -9 PID
fi
#running the jar file you
nohup java -jar /local/publish/mtc_preprint/util/LiteRail_3.0.1.jar literail.properties > /local/publish/mtc_preprint/util/Literail.log 2>&1 &
希望这对您有所帮助。
关于linux - 带有 cron 作业的 Shell 脚本在未运行的情况下启动程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27062668/