我正在开发一个Java程序,检查正在运行的进程,如果没有启动这一进程。 在我的背景,我执行.SH文件,该文件是这样的。
#!/bin/sh
echo "Hello World..."
cnt=`ps -eaflc --sort stime | grep clientApplication.jar | grep -v grep | wc -l`
if [ $cnt = 3 ]
then
echo "Services for Pigeon are already running..."
else
echo "Starting Services for Pigeon..."
echo `java -jar clientApplication.jar`
fi
但它不工作。 有什么问题?
使用测试表达的作品。 希望这可以帮助 !!
echo "Hello World"
cnt=`ps -eaflc --sort stime | grep clientApplication.jar |grep -v grep | wc -l`
if(test $cnt -eq 3) ;
then
echo "Services for Pigeon are already running..."
else
echo "Starting Services for Pigeon..."
echo `java -jar clientApplication.jar`
fi
我不确定。 尝试这个
cnt=$(`ps -eaflc --sort stime | grep clientApplication.jar | grep -v grep | wc -l`)
if[$cnt -eq 3]; then
刚刚尝试这一点
echo won't execute anything it will just print the content what is there in double quotes.
So if i have understood your requirement you should be doing this instead of
回声的“Hello World” CNT = ps -eaflc --sort stime | grep clientApplication.jar |grep -v grep | wc -l
ps -eaflc --sort stime | grep clientApplication.jar |grep -v grep | wc -l
ps -eaflc --sort stime | grep clientApplication.jar |grep -v grep | wc -l
如果(测试$ CNT -eq 3); 然后回声“的鸽子服务已经运行...”其他回声“启动服务的鸽子......” /bin/java -jar clientApplication.jar
网络
Hope this will work, i haven't tested it now
- 相等检查应==,=是分配
- 我会使用$(表达式),而不是`expr`
- 如果(表达式)不如果[expr]
- 如果你打算呼应的java线与否不能确定,它不会告诉它打印开始罐子。 既然你说你想要启动它我摆脱了回声。
所以如果你试试这个,它的工作:
#!/bin/sh
echo "Hello World..."
cnt=$(ps -eaflc --sort stime | grep clientApplication.jar | grep -v grep | wc -l)
if($cnt==3)
then
echo "Services for Pigeon are already running..."
else
echo "Starting Services for Pigeon..."
java -jar clientApplication.jar
fi