user3889810
user3889810

Reputation: 1

Linux bash -c in command shell script

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....

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'

Any help or suggestions would be great...

Thanks

Upvotes: 0

Views: 648

Answers (1)

anubhava
anubhava

Reputation: 786289

Better to use quoted here-doc and avoid escaping:

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

Upvotes: 2

Related Questions