我的shell脚本在启动时会打印分段错误。bash shell脚本显示分段错误
watchdog.sh:
#!/bin/bash
while true
do
processCnt=`ps ax | grep $1 | grep -v grep | grep -v watchdog | wc -l`
if [ $processCnt -lt 1 ]; then
$1
fi
sleep 2
done
脚本得到一个程序名作为参数。
我还在run.sh中同时运行这个脚本4次,并使用不同的参数。
run.sh:
./watchdog.sh hqservicedemon &
./watchdog.sh relayservicedemon &
./watchdog.sh rtspservicedemon &
./watchdog.sh httpcontrolservicedemon &
当我运行run.sh我得到错误:
./watchdog.sh: line xx: 7316 segmentation fault (core dumped)
一些测试运行中只运行一个watchdog.sh时,它看起来像确定后。 SH。
我在做什么错误的shell脚本?
谢谢你的任何建议。
编辑: 我的恶魔有问题,而不是脚本。修复恶魔后,脚本运行良好。
考虑使用[pgrep](http://linux.die.net/man/1/pgrep)而不是通过'grep'管道化'ps'。 – 2014-12-08 07:26:26