The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
using ssh with a for loop din Shell Programming and Scripting 4 03-05-2009 03:32 AM
while loop inside while loop panknil Shell Programming and Scripting 0 01-07-2008 12:49 PM
for loop help smtpgeek Shell Programming and Scripting 12 11-09-2005 08:04 PM
while loop whited05 Shell Programming and Scripting 2 11-03-2005 12:27 PM
how to get the similar function in while loop or for loop trynew Shell Programming and Scripting 3 06-17-2002 12:09 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-16-2009
ruben.rodrigues ruben.rodrigues is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 45
Until loop

Hi

I just want to know if this until loop is write because my script is not working and I don't know where is my error and maybe it's in this until cicle

until [ ! `cat svn.txt` -eq $pname ]
do

...
done

So basicly I want to know if I can execute that command (cat svn.txt) and if the syntax is write

Thanks in advance
  #2 (permalink)  
Old 03-16-2009
pludi's Avatar
pludi pludi is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,963
Did you try a trace with set -x? If so, was there anything unusual about it?
By the way, wouldn't it be more readable to write the loop as
Code:
while [[ "`cat svn.txt`" -eq "$pname" ]]
do
...
done

  #3 (permalink)  
Old 03-16-2009
ruben.rodrigues ruben.rodrigues is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 45
Quote:
Originally Posted by pludi View Post
Did you try a trace with set -x? If so, was there anything unusual about it?
By the way, wouldn't it be more readable to write the loop as
Code:
while [[ "`cat svn.txt`" -eq "$pname" ]]
do
...
done
well it gave me the same error. I will post my script, not because I want you to solve it for me but because I already trying this since last week and as a new guy where I need a lot of help
__________________________________________

Code:

#!/bin/sh

user=`whoami`
pname="svn `whoami`"
var=0

LOGFILE=`mktemp -t svn_checkout.XXXXXX`
ICONPATH="`dirname $0`/svn.xpm"
list=`ssh $user@192.168.1.3 "ls /esp-server/svn"`
URL=`zenity --entry --title="Subversion: Checkout" --text="$list

Enter repository folder according to the the aboves:" --entry-text="" --width=400 --window-icon="$ICONPATH" 2>&1`

#So until where is everything ok and my script work as I want. The problem was when #I wanted to add a progress bar to my script

if [ $? -eq 0 ]
then
  svn checkout svn+ssh://$user@192.168.1.3/esp-server/svn/$URL &> $LOGFILE & pid1=$!
  zenity --progress --pulsate --auto-kill & pid2=$!
  
  while [ $var -lt 1 ]
  do
    ps aux | awk '{ print $11 " " $1 }' | grep svn > svn.txt    
    
#until where is also ok

    infile=`cat svn.txt`
    echo $infile
    until [[ "`cat svn.txt`" -eq "$pname" ]]
    do
#then when it enters where I'm not sure if it works. Like, I know it goes inside the until #because the echo in the next lines are "echoed", but the until never stops and thats #very confusing because my condition is until "`cat svn.txt`" -eq "$pname" and after the svn command is done, the svn.txt is empty and so 
#[["`cat svn.txt`" -eq "$pname" ]] is true and so should go out from the until
    echo $infile
    echo $pname
    
    ps aux | awk '{ print $11 " " $1 }' | grep svn > svn.txt ;
    
    
    done

    $var=2   #this is for exit the while 
    kill $pid2 # and this to kill the progress bar
    
      
    
  done
  rm -f svn.txt
  rm -f $LOGFILE

fi

and by the way, my verbose says error line 44 which is the last if. why


Please help
thanks in advance

Last edited by ruben.rodrigues; 03-16-2009 at 04:59 AM..
  #4 (permalink)  
Old 03-16-2009
pludi's Avatar
pludi pludi is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,963
First, please edit your post and put [ code][/code ] tags around your source and reformat it properly.

Second, if you want the loop to run until svn.txt is empty again, why do you compare it with the contents of the $pname variable? If you want to find the contents of $pname in the file, use
Code:
while [[ grep -q $pname svn.txt ]]

which will do a "quite" grep, meaning only $? (the exit code) will be set.
  #5 (permalink)  
Old 03-16-2009
ruben.rodrigues ruben.rodrigues is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 45
Quote:
Originally Posted by pludi View Post
First, please edit your post and put [ code][/code ] tags around your source and reformat it properly.

Second, if you want the loop to run until svn.txt is empty again, why do you compare it with the contents of the $pname variable? If you want to find the contents of $pname in the file, use
Code:
while [[ grep -q $pname svn.txt ]]

which will do a "quite" grep, meaning only $? (the exit code) will be set.
worst. now it kill me the bar before it finishs
just tell me one thing if you know

I have a second script that looks more simple


Code:
#!/bin/sh


user=`whoami`
pname="svn `whoami`"
var=0

LOGFILE=`mktemp -t svn_checkout.XXXXXX`
ICONPATH="`dirname $0`/svn.xpm"
list=`ssh $user@192.168.1.3 "ls /esp-server/svn"`
URL=`zenity --entry --title="Subversion: Checkout" --text="$list

Enter repository folder according to the the aboves:" --entry-text="" --width=400 --window-icon="$ICONPATH" 2>&1`

if ($? == 0) then
  svn checkout svn+ssh://$user@192.168.1.3/esp-server/svn/$URL &> $LOGFILE
  zenity --progress --pulsate --auto-kill & pid=$!
  echo "`ps aux | awk '{ print $11 " " $1 }' | grep svn`"
  echo "before while"
  while [ "`ps aux | awk '{ print $11 " " $1 }' | grep svn`" -eq "svn ruben"]
  do    
    echo "`ps aux | awk '{ print $11 " " $1 }' | grep svn`"
    echo "I'm inside the while"
  done
  kill $pid
fi

echo "end"

but when I execute it gives me this

Checkout2: 26: 0: not found
end

# the end is from the echo and the line 26 is the fi
Why man? like I think that my only error
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0