Wednesday, July 31, 2013

bash while loop, function and ssh

Yesterday I struggled an entire morning with a while loop inside a bash script.
The loop ended even if there was a lot of work to do.
And the while loop ended only when I was calling a function inside another function.

The function contained an ssh call to a remote host to get a result.
Such ssh connection, opening a shell on the remote host, maybe killed my while environment?

The solution:

remote() {
  echo -e "Checking if it is the first time we zfs send to remote $1"
  ssh $sshparam zfs list $1 </dev/null &>/dev/null 
  if [ $EL -eq 0 ]
    return 1
    return 0

</dev/null &>/dev/null 

No comments:

Post a Comment