0

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
HOSTS=/opt/mgr/conf/$1serverlist.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':"
read CHOICE
case "$CHOICE" in
        y|yes|Yes) while read line
do
        ssh "$line" "mkdir -p $dest" && scp -r "$file" "$line:$dest"
done < $HOSTS
        continue ;;
     n|no|No) echo "Please try again later"

esac

And the Error:

./filepush: line 31: continue: only meaningful in a `for', `while', or `until' loop

1 Answers1

0

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.

Barmar
  • 364
  • 1
  • 8
  • 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