Linux bash -c命令shell脚本

时间:2021-07-23 15:42:49

I am using ssh in a shell script in order to go on multiple linux server and get disk information on a particular disk. I am running following but I am not able to figure out the quote sequencing...In this example I am just capturing the header for my report....

我在shell脚本中使用ssh,以便在多个Linux服务器上运行并获取特定磁盘上的磁盘信息。我正在运行以下但我无法弄清楚引用顺序...在这个例子中我只是捕获报告的标题....

ssh dbadmin@myserver bash -c '"df -kh | grep File | awk '{ print \$1 "  |  " \$2 "  |  " \$3 "  |  " \$4 "  |  " \$5 }' | tail -n -1"'

and following error...

并跟随错误......

bash: -c: line 0: syntax error near unexpected token |' bash: -c: line 0:df -kh | grep File | awk { print | | | | } | tail -n -1'

bash:-c:第0行:意外令牌附近的语法错误|' bash:-c:第0行:df -kh | grep文件| awk {print | | | | } |尾巴-n -1'

Any help or suggestions would be great...

任何帮助或建议都会很棒......

Thanks

谢谢

1 个解决方案

#1


2  

Better to use quoted here-doc and avoid escaping:

最好使用引用的here-doc并避免转义:

ssh -t -t dbadmin@myserver<<'EOF'
df -kh | awk -v OFS="  |  " '/file/{ print $1, $2, $3, $4, $5 }' | tail -n -1
EOF

#1


2  

Better to use quoted here-doc and avoid escaping:

最好使用引用的here-doc并避免转义:

ssh -t -t dbadmin@myserver<<'EOF'
df -kh | awk -v OFS="  |  " '/file/{ print $1, $2, $3, $4, $5 }' | tail -n -1
EOF