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
./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.

Also, i'm not sure this is doing what you expect:

HOSTS=/opt/mgr/conf/$1serverlist.conf

You might want to change this to:

HOSTS=/opt/mgr/conf/${1}serverlist.conf

hth

When I run the script it looks for a nonprod or prod server list conf file.

I run it like

  ./filepush nonprod

so it gets the list right.

$1serverlist.conf will look for an empty string -> .conf
As there is no variable named like $1serverlist.

${1}serverlist.conf will look for nonprodserverlist.conf .

hth

Hello gkelly1117

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.

CONF FILE:

cmap01.foobar.com
cmap02.foobar.com
cmap03.foobar.com
cmap05.foobar.com
rfap05.foobar.com
t2000.foobar.com

OUTPUT:

[sseadmin@cmap04 bin]$ ./filepush nonprod
+ source /opt/mgr/conf/file.conf
++ file=/opt/mgr/tools/jcecheck.sh
+ source /opt/mgr/conf/dest.conf
++ dest=/opt/mgr/tools
+ HOSTS=/opt/mgr/conf/nonprodserverlist.conf
+ echo 'Are you sure you want to copy /opt/mgr/tools/jcecheck.sh to the list of nonprod servers'
Are you sure you want to copy /opt/mgr/tools/jcecheck.sh to the list of nonprod servers
+ echo 'This may take a while!!'
This may take a while!!
+ echo -n 'Enter '\''y'\'' or '\''n'\'':'
Enter 'y' or 'n':+ read CHOICE
y
+ '[' y ']'
+ case "$CHOICE" in
+ read line
+ ssh cmap01.foobar.com 'mkdir -p /opt/mgr/tools'
+ scp -r /opt/mgr/tools/jcecheck.sh cmap01.foobar.com:/opt/mgr/tools
jcecheck.sh                                                                                                                           100% 1082     1.1KB/s   00:00
+ read line
+ ssh cmap02.foobar.com 'mkdir -p /opt/mgr/tools'
+ scp -r /opt/mgr/tools/jcecheck.sh cmap02.foobar.com:/opt/mgr/tools
jcecheck.sh                                                                                                                           100% 1082     1.1KB/s   00:00
+ read line
+ ssh cmap03.foobar.com 'mkdir -p /opt/mgr/tools'
+ scp -r /opt/mgr/tools/jcecheck.sh cmap03.foobar.com:/opt/mgr/tools
jcecheck.sh                                                                                                                           100% 1082     1.1KB/s   00:00
+ read line
+ ssh cmap05.foobar.com 'mkdir -p /opt/mgr/tools'
+ scp -r /opt/mgr/tools/jcecheck.sh cmap05.foobar.com:/opt/mgr/tools
jcecheck.sh                                                                                                                           100% 1082     1.1KB/s   00:00
+ read line
+ read -p 'Continue [yN] ? ' CHOICE
Continue [yN] ? y
+ '[' y ']'
+ case "$CHOICE" in
+ read line
+ ssh cmap01.foobar.com 'mkdir -p /opt/mgr/tools'
+ scp -r /opt/mgr/tools/jcecheck.sh cmap01.foobar.com:/opt/mgr/tools
jcecheck.sh                                                                                                                           100% 1082     1.1KB/s   00:00
+ read line
+ ssh cmap02.foobar.com 'mkdir -p /opt/mgr/tools'
+ scp -r /opt/mgr/tools/jcecheck.sh cmap02.foobar.com:/opt/mgr/tools
jcecheck.sh                                                                                                                           100% 1082     1.1KB/s   00:00
+ read line
+ read -p 'Continue [yN] ? ' CHOICE
Continue [yN] ?