I'm trying to ssh into a remote machine, obtain a directory listing, assign it to a variable, and then I want to be able to use that variable in the rest of the script on the local machine.
After some research and setting up all the right keys and such, I can run commands via ssh just fine. Specifically, if I do:
ssh -t user@server "ls /dir1/dir2/; exit; bash"
I do get a directory listing. If I instead do:
ssh -t user@server "set var1=`ls /dir1/dir2/`; exit; bash"
instead gives an ls error that the directory was not found. Also of note is that this happens before I am asked for the ssh key passphrase, which makes me think that it's executing locally somehow.
Any idea on how I can create a local variable with a directory listing list of the remote host in a bash script?