Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !. unfortunately this utility is third party and I cant fix it.
The utility should generate a unique 4 digit number, e.g. "5677" but when it fails it generates "0000" (and it fails more often than not)
My question is this, i want to write a while loop that tests for "0000" (i.e. failed) and if "0000" re-run the program, but at the same time, I don't want the script to continue running indefinitely, because the program may conceivably return a correct value on the 5'000th re-run or never (unlikely but you get the idea) . So i want it to give up after 20 goes
so basically, I have been attempting and failing miserably to write a script that does the following...
while $OUTPUT ="0000"; do `rerun the binary` # when it returns something other than "0000" return true and jump out of the loop... but if it continues to fail more than 20 times then give up and jump out of the loop
is this possible ? do i have to put a loop inside a loop ?
any help or advice would be greatly appreciated
---------- Post updated at 05:49 AM ---------- Previous update was at 04:48 AM ----------
sorry, I forgot to put up my example code, unfortunately, I have no means to test this but would something like this work ?
Hi there guys!
I was trying to do:
while read line; do
if ; then
read -p "Press Enter to continue..."
cont=0
fi
echo $line
let cont++
done < file.txt
However, I have read that the read -p would not work in a while loop...
I was wondering if there is any other way to... (2 Replies)
I'm taking a unix class and need to countdown to 0 from whatever number the user inputs. I know how to do this with a while or until loop but using the for loop is throwing me off....
I know I can use an if-then statement in my for loop but can I include a while loop in my for loop? (3 Replies)
Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Hi Folks,
I have a loop that goes through an array and the output is funky.
sample:
array=( 19.239.211.30 )
for i in "${array}"
do
echo $i
iperf -c $i -P 10 -x CSV -f b -t 50 | awk 'END{print '$i',$6}' >> $file
done
Output:
19.239.211.30
19.2390.2110.3 8746886
seems that when... (2 Replies)
Hi All,
Below is the very simple code snippet but it si giving me syntax error
#!/bin/bash
#To ensure If JMS directory exists or not
ServerName=$(hostname)
#To ensure If JMS directory exists or not
echo $ServerName
if ;
then
echo "Inside First If"
if ;
then
echo 'JMS... (4 Replies)
Hi, I am a newbie and would like to create a shell script that will move one file at a time from one path to another path in the same server. However, the next file should wait until the first file gets deleted by an application.
I tried creating the script but right after the first file has... (1 Reply)
I am new to unix and trying to make a script for writing all my command into another file and use that file to run all commands
I am trying to use for loop with echo command to generate a command based script for writing the file with all the command sequentially w.r.t for loop.
I want... (6 Replies)
Is it possible to have a for loop nested inside another for loop? I am trying to run a script against specific files inside a child directory but I can't seem to find a solution that is clean and affect to do it. Here is what I am trying do. I have 2 gzip files in each of the Target Directories... (4 Replies)
I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends.
As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Dear All,
i have a awk script where i'm using while loop inside while loop
here is the code:
awk -v DATE="$CURRDATE" -v -F'@' 'BEGIN {
while(( getline < "Merge_Calldet.txt" ))
{
ARR=$5
LINE=$0
while(( getline < "Merge_Accessnum.txt" ))
{
TESTSIMENTRY=$1
FILEDATE=$15 ... (0 Replies)