Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error while writing "while true do"

Status
Not open for further replies.

visvid

Technical User
Jun 3, 2002
131
GB
Hi ,

I am wanting to run this :
while true do
> ps -ef | grep -i uoq0248 | grep -v grep | wc -l
> if [ num_procs -eq 0 ]
> then
> su - oqbchprd -c nohup uoq0248 &
> sleep 10
> done
syntax error: `done' unexpected

I do not want this as a perm script , but just to keep an eye on one of the process... any idea while its not working ?

cheers

visvid
 
where is your 'fi' ? vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
vlad is right in the money...
also, you might want to assign a variable to num_procs

while true ; do
num_procs=`ps -ef | grep -i uoq0248 | grep -v grep | wc -l'
if [ num_procs -eq 0 ] ; then
su - oqbchprd -c nohup uoq0248 &
sleep 10
fi
done

crowe
 
Cheers for reply... this works ok , but if i run this from the cl rather than a script it is still looking for something to be added to done ? ie it shows done> > > > > >
how do i overcome this ?

With ref adding a variable , do you mean adding a another value i.e

echo &quot;checking for uoq0248 redemptions&quot;
if [ num_procs -eq 1 ]
then
echo &quot;Redemptions are working :)&quot;
elif [ num_procs -eq 0 ]
then
echo &quot;Redemptions need restarting&quot;
sleep 30
fi


I am not to hot on script writing

cheers visivd
 
Sorry, I made a typo.
This line:
num_procs=`ps -ef | grep -i uoq0248 | grep -v grep | wc -l'

should be ...
num_procs=`ps -ef | grep -i uoq0248 | grep -v grep | wc -l`

notice the back-tick at the end of the line instead of a single quote.

also the if statement should look like this
if [ $num_procs -eq 0 ] ; then

As far as the variable, you need to declare num_procs as something before you use use it in a comparison (the if statement).

crowe
 
Sorry crowe , treat me like an idiot,

How would i set that up ?

num_procs=1
echo &quot;$num_procs&quot;


These are the errors I am getting now

checking for uoq0248 redemptions
+ [ 1 -eq 1]
./simon[9]: test: ] missing
+ [ -eq 0]
./simon[12]: test: ] missing
+ true

Thanks in adv

visvid


 
You post didn't include the $ before the variable num_procs but by the look of your output, you have fixed that.

But to be sure, please post the script again which is giving you the problems now.
 
This is the script I am trying to write.

while true ; do
num= `ps -ef | grep -i uoq0248 | grep -v grep | wc -l`
echo &quot;checking for uoq0248 redemptions&quot;

if [$num -eq 1] ; then

echo &quot;Redemptions are working :)&quot;
elif [$num -eq 0] ; then

su - oqbchprd -c nohup uoq0248 &
echo &quot; Attempting to restart redemptions&quot;


Box is a solaris :

5.6 Generic_105181-26 sun4u sparc SUNW,Ultra-Enterprise


sleep 30

fi
done


The error messages are posted above, as mentioned I new to all this script writing , so please be patient


Regards

visvid
 
visvid:

The shell is very particular. It requires spaces between the expression and ]:


if [$num -eq 1] ; then

echo &quot;Redemptions are working &quot;
elif [$num -eq 0] ; then

try:

if [ $num -eq 1 ] ; then

echo &quot;Redemptions are working &quot;
elif [ $num -eq 0 ] ; then

Regards,


Ed


 
Finally got it to work, by dropping one argument and adding spaces:



while true ; do
num_procs=`ps -ef | grep -i uoq0248 | grep -v grep | wc -l`
echo &quot;checking for uoq0248 redemptions&quot;

if [ num_procs -eq 1 ] ;

then

echo &quot;Redemptions are working :)&quot;
else echo &quot;Redemptions are NOT working&quot;;
su - oqbchprd -c 'nohup uoq0248' &
echo &quot;Attempting to restart redemptions&quot;

fi
sleep 60
done


Thanks for the help given over the last couple of days

visvid

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top