Вопрос

I want to extract the attached iSCSI device of a remote machine

dev_by_path="/dev/disk/by-path/ip-10.1.1.240:3260-iscsi-iqn.2013-12.com.ryussi:swift1-lun-0"

DEVICE=`ssh -i key.pem root@10.0.0.2 'bash -s' << 'ENDSSH'
basename $(readlink $dev_by_path)
ENDSSH`

It gives error:

readlink: missing operand
Try `readlink --help' for more information.
basename: missing operand
Try `basename --help' for more information

However if I do

DEVICE=`ssh -i key.pem root@10.0.0.2 'bash -s' << 'ENDSSH'
basename $(readlink "/dev/disk/by-path/ip-10.1.1.240:3260-iscsi-iqn.2013-12.com.ryussi:swift1-lun-0")
ENDSSH`

then it executes successfully and echo $DEVICE gives sda. How should I execute this.

Это было полезно?

Решение

By quoting the string that ends the "here document", you've disabled subsitution for the variables contained within it. Your $dev_by_path variable is defined on the local side, not in the remotely executing shell. So, you want to expand that before executing the ssh command.

DEVICE=`ssh -i key.pem root@10.0.0.2 'bash -s' <<ENDSSH
basename $(readlink $dev_by_path)
ENDSSH`
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top