I'm having some issues with my CSH script and the command:
set XVFBCHK2 = `pgre -f 'Xvfb' | wc -l`
It seems to return inconsistent values. When it should return 1 it returns 0. I'm pretty sure that there is a the grep function is too fast and, therefore, does not catch the new instance of Xvfb following the command line:
Xvfb :1 -screen 0 1600x1200x16 >& /dev/null &
For instance, in this stretch of CSH script:
if ( $XVFBCHK == 0 && $FIJICHK == 0 ) then
set DISP=0
set SCREEN=0
Xvfb :1 -screen 0 1600x1200x16 >& /dev/null &
set XVFBCHK2 = `pgrep -f 'Xvfb' | wc -l`
echo $XVFBCHK2
if ( $XVFBCHK2 == 1 ) then
set DISP=1
set SCREEN=0
else if ( $XVFBCHK2 == 0 ) then
Xvfb :2 -screen 0 1600x1200x16 >& /dev/null &
set DISP=2
set SCREEN=0
endif
set XVFBCHK2 = `pgrep -f 'Xvfb' | wc -l`
echo $XVFBCHK2
if ( $XVFBCHK2 == 0 ) then
Xvfb :3 -screen 0 1600x1200x16 >& /dev/null &
set DISP=3
set SCREEN=0
endif
set XVFBCHK2 = `pgrep -f 'Xvfb' | wc -l`
echo $XVFBCHK2
if ( $XVFBCHK2 == 0 ) then
Xvfb :4 -screen 0 1600x1200x16 >& /dev/null &
set DISP=4
set SCREEN=0
endif
set XVFBCHK2 = `pgrep -f 'Xvfb' | wc -l`
echo $XVFBCHK2
if ( $XVFBCHK2 == 0 ) then
Xvfb :5 -screen 0 1600x1200x16 >& /dev/null &
set DISP=5
set SCREEN=0
endif
set XVFBCHK2 = `pgrep -f 'Xvfb' | wc -l`
echo $XVFBCHK2
setenv DISPLAY :$DISP.$SCREEN
elseif
echo $XVFBCHK2
echo $DISP
I can get the following output:
0
0
3
3
3
3
3
So it seems that Xvfb was executed three times, but pgrep did not catch the executions until the third one. How do I make sure it catches the first try or accurately determines that the first try Xvfb :1 failed and it should try Xvfb :2 next?