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
./filepush: line 30: continue: only meaningful in a `for', `while', or `until' loop
Remove the continue and append a ;; after "Please try again later".
As you seem to use indention, the do .. done can be indented too, only the EOF really needs to be at the beginning of the line and have no whitespace after, where as the cat > EOF can be anywhere.
With 'continue' , you may have meant something of this sort...
#!/bin/sh
source /opt/mgr/conf/file.conf
source /opt/mgr/conf/dest.conf
HOSTS=/opt/mgr/conf/${1}serverlist.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
while [ $CHOICE ]
do
case "$CHOICE" in
y|yes|Yes) while read line
do
ssh "$line" "mkdir -p $dest" && scp -r "$file"
"$line:$dest"
done < $HOSTS ;;
n|no|No) echo "Please try again later"; break ;;
esac
read -p "Continue [yN] ? " CHOICE
done
Thanks alot for your input! Great help! I am however running into a new problem with your fix that happened without the continue, which is why I put it in first place.
See below the output after running the script and see the sample conf file that has the servers list.
It seems that it doesn't always go through the entire list of servers, it will start a loop then go halfway, then stop.