line count with if /else - syntax errors

this is the script:

ps -ef|grep "x_jobstat 10 v001" > jobstatv001.txt
ps -ef |grep "x_jobserver 10 v001" >> jobstatv001.txt
#Sample text - each line preceded by 4 spaces
#    root 133064 102986   0 08:49:28  pts/6  0:00 grep x_jobstat 10 v001
#    root 137550      1   0   Nov 08      -  0:28 x_jobstat 10 v001
#    root  82522      1   0   Nov 08      -  0:59 x_jobserver 10 v001
#    root 159334 102986   0 08:51:12  pts/6  0:00 grep x_jobserver 10 v001
# count lines
pg /jobstatv001.txt|awk '
/^ / {
   ++linenum
}'
if (linenum = 4)
 exit 1
else if (linenum = 0)
 cp /Medic/db/v001/jobserver.log /Medic/db/v001/jobserver001.log
 startjs v001
fi

this is what I get:

jschk.sh[17]: syntax error at line 19 : `else' unexpected

The file jobstatv001.txt is created.

I have also tried just a plain "if/else/fi" but still get the syntax error.
Using IBM AIX.

Please use code tags.

then what?

 
(
if ( true )
then
 echo true
else
 echo false
fi
if ( false )then
 echo true
else
 echo false
fi
)
true
false

Another way to do the job:

linenum=$(ps -ef | awk '/x_jobstat 10 v001/ || /x_jobserver 10 v001/{n++}END{print n}')

if [ "$linenum" -eq 4 ]
then
  exit 1
elif [ "$linenum" -eq 0 ]
then
  cp /Medic/db/v001/jobserver.log /Medic/db/v001/jobserver001.log
  startjs v001
fi
1 Like

Franklin - tks will try that one out!!

Being new to this forum I have NO IDEA how to convert to code tags... Sorry.
I think I can covert back tho.

Code tags are a button just left of php, adds [ + CODE + ] before and [ + / + CODE + ] after to instruct the server on formatting.

[/CODE]

1 Like

PERFECTO and thanks a bunch! will remember in the future!!