Hello,
I want to execute remote command with ssh.
For exemple, i have a variable
SERVERS=lpar1,lpar2,lpar3
I want to execute some commands like:
ssh -q lpar1 ls /
ssh -q lpar2 ls /
ssh -q lpar3 ls /
Can you help me with awk command ?
Thank you
Hello,
Following may help you in same.
SERVERS=lpar1,lpar2,lpar3
Actual_SERVERS=`echo $SERVERS | sed 's/,/ /g'`
set -A array_SERVERS $Actual_SERVERS
for a in ${array_SERVERS[@]}
do
echo "ssh -q " $a "ls /"
done
Output will be as follows.
ssh -q lpar1 ls /
ssh -q lpar2 ls /
ssh -q lpar3 ls /
Thanks,
R. Singh
It's good !!!
It is possible to do it with awk function ?
Thank you very much
Hello,
here is the same as requested.
echo "lpar1,lpar2,lpar3" | awk -F"\," '{for(i=1;i<=NF;i++) {print "ssh -q " $i " ls /"}}'
Output will be as follows.
ssh -q lpar1 ls /
ssh -q lpar2 ls /
ssh -q lpar3 ls /
Thanks,
R. Singh
Yoda
March 10, 2014, 1:21pm
7
I don't know why you requested for a solution based on awk! I think it is an overkill when you can do it simply in shell:
SERVERS=lpar1,lpar2,lpar3
for host in ${SERVERS//,/ }
do
ssh -q $host "ls /"
done