在远程机器上执行 readlink [英] Execute readlink on a remote machine

查看:55
本文介绍了在远程机器上执行 readlink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提取远程机器的附加 iSCSI 设备

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`

它给出了错误:

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

但是如果我这样做

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`

然后它成功执行并且echo $DEVICE给出sda.我应该如何执行此操作.

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

推荐答案

通过引用结束here document"的字符串,您已禁用对其中包含的变量的替换.您的 $dev_by_path 变量是在本地定义的,而不是在远程执行的 shell 中.所以,你想在执行 ssh 命令之前扩展它.

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`

这篇关于在远程机器上执行 readlink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆