I am getting successful output when i run below script. What i am trying here is, i should connect to all below VM's listed and when script ssh to wasadmds03 then it should print output as product detail, similarly for other VM's and also it should execute the command
"cat /source/package.json | grep version" on all VM's.
I am getting the output what i need - but is there a way to trim the repeated "if then" statement? I have used "if then" statement four times, imagine if i want to do the similar exercise for 50 VM's is there a way to write this program in a shorter way?
wasadmds03 - product detail
wasadmds04 - product list
wasadmls03 - Cart
wasadmls05 - checkout
- Script
**
#!/bin/bash
for i in `cat /tmp/ms_test`
do
if [ $i = wasadmds03 ]
then
echo "Product Detail"
ssh $i "cat /source/package.json | grep version"
fi
if [ $i = wasadmds04 ]
then
echo "Product list"
ssh $i "cat /source/package.json | grep version"
fi
if [ $i = wasadmls03 ]
then
echo "Merchant"
ssh $i "cat /source/package.json | grep version"
fi
if [ $i = wasadmls05 ]
then
echo "Account Details"
ssh $i "cat /source/package.json | grep version"
fi
done
/tmp/ms_test? – Kusalananda Apr 19 '20 at 06:57