문제

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