1

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.

Capricorn
  • 701
  • 1
  • 10
  • 20

1 Answers1

1

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`
Mike Andrews
  • 3,045
  • 18
  • 28
  • Here's what i did: `cmd_file=mktemp echo "basename \$(readlink $dev_by_path)" > $cmd_file DEVICE=``ssh -i $STORAGE_KEY.pem -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null root@$storage_ip 'bash -s' < $cmd_file` – Capricorn Dec 30 '13 at 06:21