Awk and meminfo

I'm in the process of adding various data to my rrdtool setup, and one of the things i want ot monitor is the meminfo stuff.

I have it running locally very well with the following:

/usr/bin/rrdupdate /etc/rrdtool/192.168.43.254.mem.rrd --template \
    used:free:buff:cached:swap N:`awk ' \
    /^MemTotal:/    {total=$2*1024}
    /^MemFree:/     {free=$2*1024}
    /^Buffers:/     {buff=$2*1024}
    /^Cached:/      {cached=$2*1024}
    /^SwapTotal:/   {swaptotal=$2*1024}
    /^SwapFree:/    {swapfree=$2*1024}
    END {
        used=total-(free+buff+cached)
        swap=swaptotal-swapfree
        print used ":" free ":" buff ":" cached ":" swap
    }' /proc/meminfo`

But when I try and run an SSH command prior to this, i.e. for a remote server, I get errors. Can someone give me a clue as to what I'm doing wrong?

/usr/bin/rrdupdate /etc/rrdtool/192.168.43.253.mem.rrd --template \
    used:free:buff:cached:swap N:`ssh 192.168.43.253 "awk ' \
    /^MemTotal:/    {total=$2*1024}
    /^MemFree:/     {free=$2*1024}
    /^Buffers:/     {buff=$2*1024}
    /^Cached:/      {cached=$2*1024}
    /^SwapTotal:/   {swaptotal=$2*1024}
    /^SwapFree:/    {swapfree=$2*1024}
    END {
        used=total-(free+buff+cached)
        swap=swaptotal-swapfree
        print used ":" free ":" buff ":" cached ":" swap
    }' /proc/meminfo"`

Thanks
James

Save your script in a file and call it on the remote server like the following.

ssh user@server "bash -s " < script.sh

Thanks for the reply....

I was hoping not to have to put the script of the remote server, but if needs must!

Also, not sure what the "bash -s" was meant for, as it didn't work, but the following has worked:

ssh user@server /bin/sh /etc/script.sh

Thanks
Nunners