Bash: Repeat commands until a condition is matched
Hi everybody, i need to modify some scripts to repeat the commands in them until a variable returns a proper value. I need it to add some redundancy to some scripts i use to upload files to a remote server.
This is an example of a portion of those scripts: Code:
################## site UPLOAD ################## Any idea on how to do it? I guess a WHILE is needed, but i never used it, so i'm not sure on where to place it or how to write it. Thanks. |
An until seems to fit better into the logic of what your script is doing.
The general format of an until loop is: Code:
until test-commands; do consequent-commands; done In your case I'd say you'll want to modify your script along the lines of: Code:
You'll most likely want to wait some between your posts so you don't flood the server and possibly also include some other exit conditions like max number of tries. |
OT - I was just wondering what value the 'sed q' gives at the end of site_link command substitution?
|
Quote:
|
Thanks z1p, yours is a good solution. Everything changes if i output the result_site to a txt file, use a WAIT, and then read the site_link from that TXT, i willpost some exampla later.
@ grail and reuti The sed -q was used because the regex returned two or more lines, while i just needed one of them. |
All times are GMT -5. The time now is 08:30 PM. |