I pulled the nixCraft line-by-line processing script, and edited it to search for and modify a pattern, save the modified pattern to a temp file, then scp the modified file to a remote host.
This works beautifully for the first line in a file containing two arguments per line: the string to insert in the sed search and replace above, and the ip address of the target host
contents of FILE:
100 10.1.1.1
200 10.1.1.2
300 10.1.1.3
.
.
3100 10.1.1.31
This subroutine just works on line one of FILE:
Code:
# User define Function (UDF)
processLine(){
line="$@" # get all args
ID=$(echo $line | awk '{ print $1 }')
Coll_ID="id="$ID""
Coll_IP=$(echo $line | awk '{ print $2 }')
echo "Setting Collector at $Coll_IP to be AD ID $Coll_ID"
# writing temporary file on local system
# this version of sed does not support -i
sed -e "s/id=[0123456789]*/$Coll_ID/" /<path>/<filename1> > <tempfile>
# copying temp file to target
scp <tempfile> root@"$Coll_IP":/<targetpath/<targetfile>
# Now showing contents of remote file to verify the change
echo "This is the modified line from $Coll_IP"
ssh -l root "$Coll_IP" grep -e "id=" /<targetpath>/<targetfile>
echo -e "\n"
}
Generated output:
Quote:
Code:
Setting Collector at 10.1.1.1 to be AD ID 100
<tempfile> 100% 253 0.3KB/s 00:00
This is the modified line from 10.1.1.1
/<targetpath>/<targetfile>:id=100
|
As can be seen, lines 2 and beyond of FILE are not processed, so there are 30 other systems that do not get the file pushed out to them.
Now, if I just echo the two arguments, all lines are processed:
Code:
# User define Function (UDF)
processLine(){
line="$@" # get all args
ID=$(echo $line | awk '{ print $1 }')
Coll_ID="id="$ID""
Coll_IP=$(echo $line | awk '{ print $2 }')
echo "$Coll_ID and $Coll_IP"
}
Generated output:
Quote:
id=100 and 10.1.1.1
id=200 and 10.1.1.2
id=300 and 10.1.1.3
.
.
.
id=3100 and 10.1.1.31
|
Yes, all target systems are set to use passwordless scp, all target keys are on local system.
I've tried moving the procedure processLine to a completely different script, with the same results.
Any ideas? Google has not been my friend so far...
Regards,
Scott