0

hello I have a command

echo $(ssh [email protected] 'zfs list -o name -t snapshot | grep tank/dema@Daily_$(date +"%Y-%m-%d") | wc -l')

this returns a integer value I need to while loop over it but can't seem to figure out who to do that.

while echo $(ssh [email protected] 'zfs list -o name -t snapshot | grep tank/dema@Daily_$(date +"%Y-%m-%d") | wc -l') -g 1; do

echo stuff

done
4
  • What is the intention of the -g param? And what is the output of the command echo $(ssh [email protected] 'zfs list -o name -t snapshot | grep tank/dema@Daily_$(date +"%Y-%m-%d") | wc -l') -g 1 and echo $(ssh [email protected] 'zfs list -o name -t snapshot | grep tank/dema@Daily_$(date +"%Y-%m-%d") | wc -l') Commented Apr 16, 2015 at 6:46
  • What do you mean by "while loop over it"? Do you need to call that long command on each iteration? Do you iterate until the integer is zero, or what? Commented Apr 16, 2015 at 6:53
  • Sorry the output of the command is a integer like 6 or 10 ect. I want to loop over it while output > 1. Also it needs to call said command each loop to make sure it's still greater then 1. Thanks for the help. Commented Apr 16, 2015 at 6:54
  • 1
    while keeps looping as long as that condition is true (returns a 0 exit status). So what exactly do you observe when executing your code above? That the code inside of the while loop is never executed? Commented Apr 16, 2015 at 7:08

1 Answer 1

1

Hi You can try like this,

declare -i value
value=`echo $(ssh [email protected] 'zfs list -o name -t snapshot | grep tank/dema@Daily_$(date +"%Y-%m-%d") | wc -l')`
while [ "$value" -gt 1 ]; do
    echo stuff
    value=`echo $(ssh [email protected] 'zfs list -o name -t snapshot | grep tank/dema@Daily_$(date +"%Y-%m-%d") | wc -l')`
done

OR we can use it like,

declare -i value
while : ; do
  value=`echo $(ssh [email protected] 'zfs list -o name -t snapshot | grep tank/dema@Daily_$(date +"%Y-%m-%d") | wc -l')`
  [[ "$value" -gt 1 ]] || break
  echo stuff
done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.