You are not logged in.
Hi all,
I'm trying to execute commands on another server via ssh in a script. This works, I get a listing of the /boot directory of the slave server:
#!/bin/bash
bootdiratslave=$(ssh 192.168.31.106 -i ~/slaveroot 'ls /boot/')
echo $bootdiratslave
This does not work, I get a listing of the / directory of the slave server:
#!/bin/bash
slave_dir="/boot"
bootdiratslave=$(ssh 192.168.31.106 -i ~/slaveroot 'ls /$slave_dir')
echo $bootdiratslave
I think the variable slave_dir is not known at the slave server, so /$slave_dir expands to /
how can I use variables in ssh statements?
Last edited by cdwijs (2021-02-07 07:35:54)
Offline
Use soft (i.e. double) quotes for that ls rather than hard (i.e. single) quotes.
Note this is not a question relating to ssh etc. The shell simply won't expand anything within hard quotes.
Last edited by bulletmark (2021-02-07 07:27:23)
Offline
It works, thank you for your fast answer.
My apologies for posting this in the wrong section.
Offline