Sample Header Ad - 728x90

Storing values from loop and comparing them every time run the script

1 vote
0 answers
588 views
### Description Hello, I'm trying to loop over certain commands and save their outputs into a file, and while looping through those commands, also check the file which we saved their outputs so we can compare them from the file while looping the commands at the same time. In the end, check if the looped commands' outputs match with the previously saved outputs in that file. *(Also check if the file doesn't contain the output and add it into the file so we can later use it to compare again)* This is my main script which loops through the said commands which are located inside /usr/local/bin/ so I can run them directly from the shell.
#!/bin/bash
wallets=find /usr/local/bin/ -iname '*-cli'

for i in $wallets; do
    current_blocks=$I getblockcount
    coin_name=${i:15:-4} # I use :15:-4 here to cut the path and the last 4 characters. (For example it's /usr/local/bin/bitcoin-cli so I change it to bitcoin only
    echo $coin_name $current_blocks
    echo $coin_name $current_blocks >> blocks.log
done
And this echo gives us exactly this (assuming there are 2 items in the $wallets;
bitcoin 1457824
litecoin 759345
And this is the while loop I will -presumably- be using to read from the file;
while read line ; do
    set $line
    echo $1 $2
done = "$2" )); then
				echo "Current blocks are greater than the saved blocks"
				echo "Saving the new blocks count now"
				sed -i "s/$1/$1 $current_blocks/" blocks.log
			else
				echo "Current blocks are less than or equals to saved blocks"
			fi
		else
			echo "File does not contain the coin_name, adding it now"
			echo "$coin_name $current_blocks" >> blocks.log
		fi
	done = "$2" )); then
            echo "Current blocks are greater than the saved blocks"
            echo "Saving the new blocks count now"
            # sed -i "s/$1/$1 $current_blocks/" blocks.log
        else
            echo "Current blocks are less than or equals to saved blocks"
        fi
    else
        echo "File does not contain the coin_name, adding it now"
        echo "$coin_name $current_blocks" >> blocks.log
    fi

done
What am I doing wrong?
Asked by Marry Jane (151 rep)
Feb 19, 2019, 09:45 PM
Last activity: Feb 19, 2019, 11:19 PM