$ /usr/bin/ssh user@server "sudo sysdumpdev -e |awk '{print \$7}' |awk '{size=\$1/1024/1024; printf("%d\n", size);}'"
Syntax Error The source line is 1.
The error context is
{size=$1/1024/1024; >>> printf(% <<< dn, size);}
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
答案1
您必须转义双引号内的双引号:
/usr/bin/ssh user@server "sudo sysdumpdev -e |awk '{print \$7}' |awk '{size=\$1/1024/1024; printf(\"%d\n\", size);}'"
这两个awk
命令可以合二为一:
/usr/bin/ssh user@server "sudo sysdumpdev -e |awk '{printf(\"%d\n\", \$7/1024/1024);}'"
awk
另一种方法是在本地计算机上运行命令:
/usr/bin/ssh user@server sudo sysdumpdev -e |awk '{print $7}' |awk '{size=$1/1024/1024; printf("%d\n", size);}'
/usr/bin/ssh user@server sudo sysdumpdev -e |awk '{printf("%d\n", $7/1024/1024);}'
编辑:引用戴夫·汤普森_085的评论
虽然我更喜欢本地格式,但您可以将远程格式简化为
ssh u@s "sudo sysdumpdev -e | awk '{print int($ 7/1024/1024)}' "
--$ 7
不被本地 shell 视为参数,但被(远程)awk 视为字段