i am trying to process a list of values in FILE like this:
aaa:bbb
ccc:ddd
eee:fff
With the following logic:
for INFO in FILE
do
export F1=`cut -f1,3,5,7 -d":" < FILE`
export F2=`cut -f2,3,5,7 -d":" < FILE`
ssh $F1 bash <<EOF
echo $F1
echo $F2
date
EOF
done
The problem I am finding is that the cut is extracting ALL values in the first column of FILE and the script is erroring because the second row value is not being handled.
Is there anyway I can have the script process ie cut the first row in turn, do the ssh and then do the second row and third in turn?
Are trying to read the values separated by colon ( into two different variables ? If so, you can use while loop to iterate throught the file and read the columns into variables using awk command:
so I have a file with values:
aaa:bbb
ccc:ddd
eee:fff
And the logic is thus:
for each row in turn,
ssh to host with first value of first row
echo second value of first row
exit
ssh to host with first value of second row
echo second value of second row
exit
ssh to host with first value of third row
echo second value of third row
exit
while read line
do
column1=`echo $line|awk -F":" '{print $1}'`
column2=`echo $line|awk -F":" '{print $2}'`
echo "column1 = $column1"
echo "column2 = $column2"
## After you get the values in two diff variables, use them to do whatever you want.
done < file.txt