Passing Values to remote server

I'm trying to pass there values from the present server to the remote server. here is the below code.

function abc() {

export a=$1
export b=$2
export c="$3"
export d="$4"

#servers
Servers=$(echo server40{1..3}p.s.com)

for host in ${Servers};
do

#server login
ssh $host /bin/bash <<\EOF

echo $a a
echo $b b
echo $c c
echo $d d

EOF
done
}

#functioncall
abc 34 56 xxxx yyyy;

but i'm getting blank for those variables wen i switch to other server even though i exported the variables. Please help me out what should be done.

---------- Post updated at 05:24 AM ---------- Previous update was at 05:08 AM ----------

i tried to pass like below

ssh $host "$a $b $c $d" /bin/bash <<\EOF

aa=$1
bb=$2
cc=$3
dd=$4

echo $aa aa
echo $bb bb
echo $cc cc
echo $dd dd

EOF

but i'm getting below error

bash: 3: command not found
bash: 3: command not found
bash: 3: command not found

is the way i'm passing is right?

You need quotes.

Servers="$(echo server40{1..3}p.s.com)"

Maybe you could write the commands to a file, scp it to the servers and then execute it.

echo "..." > cmdfile
for host in $Servers; do
    scp cmdfile $host;
    ssh $host ". cmdfile; rm ~/cmdfile"
done

---------- Post updated at 01:17 PM ---------- Previous update was at 01:13 PM ----------

Actually, you were right. You don't need quotes. Although it's good style to include them.

From 'man ssh:'

Sooo, just before ssh-ing, you could create a new environment file:

...
a=$1 ; b=$2; 
varFile=~/.ssh/environment
[[ -f $varFile ]] && cp ${varFile}{,.orig} #backup if exists
cat > $varFile <<EOF
a=$a
b=$b
EOF

ssh host

[[ -f ${varFile}.orig ]] && mv ${varFile}{.orig,} #revert if necessary

but make sure PermitUserEnvironment is enabled in sshd_config on server side.

Are you sure bash is in /bin on the hosts? NetBSD machines put it in /usr/pkg/bin.

I just tried this and it worked. It also worked when I used sh instead of bash.

TEST=abc
ssh somehost bash <<EOF
> echo $TEST test
> EOF
abc test

Actually it needs to execute in 3 servers.. i need the values in the present local server to be passed to all the 3 servers when they are executing

---------- Post updated at 05:42 AM ---------- Previous update was at 05:39 AM ----------

It will work fine if its just an echo statement to display the value. but in case if its a path.

a=/tmp/user/log/

in this case this path wont be present in the local server but it'll be present in the remote server that i'm logging in.
when i tried like the way you instead it was searching for the path in the same server not in the remote server.