my shell script prints segmentation fault when it starts.
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
Script gets a program name as a parameter.
I also run this script 4 times with different parameter at the same time in run.sh.
run.sh :
./watchdog.sh hqservicedemon &
./watchdog.sh relayservicedemon &
./watchdog.sh rtspservicedemon &
./watchdog.sh httpcontrolservicedemon &
When I run run.sh I get error:
./watchdog.sh: line xx: 7316 segmentation fault (core dumped)
After some tests it looks like OK when running just one watchdog.sh in run.sh.
What am I doing wrong in shell script?
Thank you for any advice.
Edited: My demon has a problem, not a script. After fix demon, script works well.
ps
throughgrep
.