Svp57
Svp57

Reputation: 318

Evaluate and assign variables inside ssh session in shell script

I'm trying to increment indx and eindx values inside a ssh session.but none of commands are working..

#!/bin/bash
hosts=( #10.xx.xx.xx )
PdidPrefix1=$1
Runtime=$2
indx=$3
eindx=`expr $indx + $4`
logfilename=$5
for i in "${hosts[@]}"
do
echo $i
ssh centos@$i << EOF
for var in {1..4}
do
indx=`expr $eindx + 1` // not working
eindx=$((indx+eindx))  // not working
done
EOF
done
exit

tried using let also

let "indx=indx+1" //not working

Kindly suggest best way to handle variables.

Upvotes: 1

Views: 548

Answers (2)

Ashim Paul
Ashim Paul

Reputation: 100

I have run the same script. And it shows the proper value.

Upvotes: 0

Ashim Paul
Ashim Paul

Reputation: 100

#!/bin/bash
hosts=( xx.10.20.30 )
PdidPrefix1=$1
Runtime=$2
indx=$3
eindx=`expr $indx + $4`
logfilename=$5
for i in "${hosts[@]}"
do
echo $i
ssh centos@$i "bash -s --  '$indx' '$eindx'" <<\EOF

echo "In remote shell with parameters $1 $2..."
indx=$1
eindx=$2

for (( var=1; var<=4; var++ ))
do

indx=`expr $eindx + 1`
eindx=$((indx+eindx))
echo "var=" $var " indx=" $indx " eindx=" $eindx
done
EOF
done
exit

Upvotes: 2

Related Questions