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 [email protected] '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 [email protected] '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.