All,
I have set up ssh trust between 3 machines. The aim is to connect from machine-A to B and C and clear the txt files in tmp on all 3 machines. And, I have 3 environments and each environment has 2 hosts. So I should be able to run this script on any environment.
Here is the logic:
I want to see if my current hostname is part of any of these 3 sections/environments, if yes, then go into that section only and do stuff. That is clear the txt only for that section and exit out.
But this isnt working as expected. It does the job but after clearing the txt, it moves onto next section/environment instead of exiting out.
I think nested for isnt working as expected or maybe I shouldnt use nested for in the first place! Please let me know if you have any better ideas to make this work.
Here is the script:
##This script will clear the txt in tmp in both local and remote locations
#!/bin/sh
EXTSSSERVERLIST=ext1.test.com,ext2.test.com
APPSSSERVERLIST=app1.test.com,app2.test.com
FAASERVERLIST=faa1.test.com,faa2.test.com
echo "Clearing txt for Test Domain..."
host=$(hostname)
echo $host;
for $(hostname) in $EXTSSSERVERLIST;
do
for f in $(echo $EXTSSSERVERLIST | tr "," " ");
do
ssh $f "rm -rf /tmp/*.txt"
done
done
for $(hostname) in $APPSSSERVERLIST;
do
for f in $(echo $APPSSSERVERLIST | tr "," " ");
do
ssh $f "rm -rf /tmp/*.txt"
done
done
for $(hostname) in $FAASSSERVERLIST;
do
for f in $(echo $FAASSSERVERLIST | tr "," " ");
do
ssh $f "rm -rf /tmp/*.txt"
done
done