Script to Push Files Hey Guys, Thanks for always being helpful, I have another issue that I need a little insight on how to fix.

See the below script I have and the error I get. I don't understand why it does that, am I not using the continue correctly?

#!/bin/bash -x
# @(#) File: filepush.sh
# ---------------------------------------------------------------------------
# Modication History:
# Date       Name                       Description
# 12/10/2014  Emmanuel Iroanya          Script to copy a file to all hosts listed in serverlist  file
# ---------------------------------------------------------------------------

source /opt/mgr/conf/file.conf
source /opt/mgr/conf/dest.conf

echo "Are you sure you want to copy $file to the list of $1 servers"
echo "This may take a while!!"
echo -n "Enter 'y' or 'n':"
case "$CHOICE" in
        y|yes|Yes) while read line
        ssh "$line" "mkdir -p $dest" && scp -r "$file" "$line:$dest"
done < $HOSTS
        continue ;;
     n|no|No) echo "Please try again later"


And the Error:

./filepush: line 31: continue: only meaningful in a `for', `while', or `until' loop
  • Your continue statement outside of while done block – Navern Dec 12 '14 at 22:48
  • what do you suggest I do then? Please? – gkelly1117 Dec 15 '14 at 15:05

Just get rid of the continue command, it's not needed. Leave the ;;, though -- that's how the end of a case is indicated.

The purpose of continue is to skip the remainder of a loop body, and start the next iteration. It has no meaning outside a loop, so you get this error. This isn't like C/Javascript/PHP -- you don't need a special statement at the end of a case to prevent falling through to the next case.

  • so when I take the continue out but leave the ;; it reads like 2 lines from the conf and thats it. – gkelly1117 Dec 15 '14 at 14:47
  • Use ssh -n. Otherwise, ssh reads all the rest of the standard input, and sends it to the server. – Barmar Dec 15 '14 at 16:20
  • Have you looked at pscp and prsync, which allow you to do parallel scp and rsync commands? rsync will automatically create directories as necessary, so you don't need the separate ssh command. – Barmar Dec 15 '14 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.