不是有效的标识符 - 执行

时间:2015-12-03 11:39:56

标签: bash unix

我尝试在shell脚本中捕获进程ID时出现以下错误.....

$bash ./restartjbossserver.sh
./restartjbossserver.sh: line 10: `i=$(ps -ef | grep "jboss" | grep -v "grep" | awk '{print $2}')': not a valid identifier

这是我的剧本......

for i=$(ps -ef | grep "jboss" | grep -v "grep" | awk '{print $2}')
do
echo $i
if [ $i != NULL ]
then
echo "Killing JBos Process.."
kill -9 $i
echo "Killed Joss Process..."
fi
done


sleep 10s

echo "Deleting JBoss Cache..."

rm -rf /home/cbsmsblapp/opt/EAP-6.3.0/jboss-eap-6.3/domain/tmp/*
echo " Deleted JBoss Cache..."


sleep 10s

nohup /home/cbsmsblapp/opt/EAP-6.3.0/jboss-eap-6.3/bin/domain.sh  & >nohup.out

2 个答案:

答案 0 :(得分:3)

迭代列表的语法是

{{1}}

{{1}}

答案 1 :(得分:1)

查看pkillpgrep命令。你可以pkill jboss