Hi all,
I am attempting to port a bash script that worked fine on RedHat 7.1 to Fedora Core 1. I am having trouble reading a file into a variable. Nothing gets read into the variable. The source file has not changed.
Sample source file:
4.40.0.0/19
12.211.156.0/22
12.221.220.0/22
It goes on for 454 lines or so.
I copied the troublesome section into a test script
#! /bin/bash
BlockedHosts="/etc/rc.d/blocked.lst"
if [ -f "$BlockedHosts" ]; then
while read ATTACKERS; do
echo "$ATTACKERS" > /dev/null
done < "$BlockedHosts";
fi
echo "$ATTACKERS"
When I run my test script, the result is a blank line.
I also tried this mod with no success based on another post in this forum.
#! /bin/bash
BlockedHosts="/etc/rc.d/blocked.lst"
if [ -f "$BlockedHosts" ]; then
cat ${BlockedHosts} | while read ATTACKERS; do
echo "$ATTACKERS" > /dev/null
done < "$BlockedHosts";
fi
echo "$ATTACKERS"
I did not come up with the first version of the code, I merely copied it from the previous script that worked on the RH7.1 that my coworker created. He can't figure it out either. He said this problem started on RedHat 8.
I am not quite a newbie, but close enough...
Thanks for any assistance