使用时
df -h | grep /dev/root | awk '{print $5}'
Run Code Online (Sandbox Code Playgroud)
我在我的 Pi 中使用了我的 SD 卡: 78%
但是当我使用
/usr/bin/ssh -i /path/to/key user@server "df -h | grep /dev/root | awk '{print $5}'"
Run Code Online (Sandbox Code Playgroud)
从另一台计算机,我得到:
/dev/root 7.2G 5.3G 1.6G 78% /
Run Code Online (Sandbox Code Playgroud)
完整df -h:
Filesystem Size Used Avail Use% Mounted on
/dev/root 7.2G 5.3G 1.6G 78% /
devtmpfs 364M 0 364M 0% /dev
tmpfs 368M 68K 368M 1% /dev/shm
tmpfs 368M 5.2M 363M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 368M 0 368M 0% /sys/fs/cgroup
/dev/mmcblk0p1 60M 21M 40M 35% /boot
tmpfs 74M 4.0K 74M 1% /run/user/1000
Run Code Online (Sandbox Code Playgroud)
Ste*_*ris 18
您遇到了引用问题;在$5被在错误的时间解释。至少有两种解决方案:
\在$;之前放一个 例如
/usr/bin/ssh -i /path/to/key user@server "df -h | grep /dev/root | awk '{print \$5}'"
Run Code Online (Sandbox Code Playgroud)
df远程运行grep和awk本地。例如
/usr/bin/ssh -i /path/to/key user@server df -h | grep /dev/root | awk '{print $5}'
Run Code Online (Sandbox Code Playgroud)
FWIW,我会运行第二个选项的版本,但合并grep和awk
/usr/bin/ssh -i /path/to/key user@server df -h | awk '/\/dev\/root/ {print $5}'
Run Code Online (Sandbox Code Playgroud)
这应该有效:
/usr/bin/ssh -i /path/to/key user@server "df -h | grep /dev/root | awk '{print \$5}'"
Run Code Online (Sandbox Code Playgroud)
注意\包含在$. 如果没有这个,本地 shell 将扩展空变量$5并将其发送到远程服务器。本质上,打印整条线。