I have a script that reads a main list, call it List A using a while loop.
List A:
east-1-1
east-1-2
east-1-3
east-1-4
east-1-5
east-1-6
east-1-7
west-1-1
west-1-10
south-1-1
south-1-2
north-1-1
What I would like to do is check it against this list:
east-1-1
east-1-3
east-1-7
west-1-10
south-1-2
As listed in my case and for each of those items in my case I would like to flag down with an *
case "${cluster}" in
east-1-1)
echo "${cluster}:${getCount} * ";;
east-1-3)
echo "${cluster}:${getCount} * ";;
east-1-7)
echo "${cluster}:${getCount} * ";;
west-1-10)
echo "${cluster}:${getCount} * ";;
south-1-2)
echo "${cluster}:${getCount} * ";;
esac
I am doing this within a function and using a case statement, however I think I'm doing this wrong and would like to know if there's a better way? Should I be using an if-then-else? Can I do this with the case?
If I could please get some help on this approach or if there's a better way to write this.
CODE IN PROGRESS:
#!/usr/local/bin/bash
MAP=./.clusterinfo
if ! [ -f "$MAP" ]; then
echo "Cluster Map not found."
exit 1
fi
while IFS='' read -r cluster; do
#Function runQuery
runQuery()
{
getCount=$(PGPASSWORD=Abc123Pa55word psql -h myapp-"${cluster}".foobar.com -U foo -d dev -p 5439 -t -c "select count(*) from pg_database;")
case "${cluster}" in
east-1-1)
echo "${cluster}:${getCount} * ";;
east-1-3)
echo "${cluster}:${getCount} * ";;
east-1-7)
echo "${cluster}:${getCount} * ";;
west-1-10)
echo "${cluster}:${getCount} * ";;
south-1-2)
echo "${cluster}:${getCount} * ";;
esac
echo "${cluster}:${getCount}"
}
#Execute
runQuery
done < "$MAP"
Current Output:
east-1-1: 50 *
east-1-1: 50
east-1-2: 8
east-1-3: 58 *
east-1-3: 58
east-1-4: 5
east-1-5: 5
east-1-6: 4
east-1-7: 30 *
east-1-7: 30
west-1-1: 4
west-1-10: 50 *
west-1-10: 50
south-1-2: 30 *
south-1-2: 30
Expected Output:
east-1-1: 50 *
east-1-2: 8
east-1-3: 58 *
east-1-4: 5
east-1-5: 5
east-1-6: 4
east-1-7: 30 *
west-1-1: 4
west-1-10: 50 *
south-1-2: 30 *