Run a remote awk command using ssh

2019-02-21 02:39发布

I try to run a remote awk statement using ssh. My code is:

ssh username@hostIP "awk 'NR==1  {max=0;min=1} NR>1 {if (max<\$3) max=\$3}END {print max}' FS=\",\" /path_to_my_file"

When I run this command, I receive no error message, but command is not working and doesn't produce an output but just hanging so I would need to cancel it by ctrl+c.

Is there something I am missing?

标签: bash shell ssh awk
1条回答
家丑人穷心不美
2楼-- · 2019-02-21 03:14

Try this using a here-doc :

ssh -t username@hostIP <<'EOF'
awk '
    NR==1 {max=0;min=1}
    NR>1 {if (max<$3) max=3}
    END {print max}
' FS="," /path_to_my_file
EOF

The single quotes around EOF prevent shell expansion.

查看更多
登录 后发表回答