I have a shell script where I am executing ls command from different hosts within it but I am having trouble achieving this. Here is my colde below:
#!/bin/sh
nodes="hostname1 hostname2"
cmd="ls -ltrha"
for node in ${nodes}; do
ssh ${node} '`$cmd`'
done
The problem with this code is that it can ssh hostname1 perfectly but it doesn't even execute the ls command or even ssh hostname2.
Any idea what I am doing wrong here?
****New Edit**** I also tried the below one liner, but it only executed the ls without the ssh
ssh hostname1 'ls -ltrha'