I need to get result of which process is using most swap space on a remote server. I am using below command which works fine if I log on to remote and run it, but it gives no output if I run it by using ssh to remote. I need to use ssh as I'll be doing this for multiple servers in a script
ssh someserver "for file in /proc/*/status; do awk '/VmSwap|Name/{printf $2 " " $3} END{print ""}' $file; done | sort -k 2 -n -r | head -1 | awk '{print $1}'"
I also tried using suggestions from previous questions on ths portal to enclose complete command in single quotes and awk in double quotes but that errors out for me as the double quote in printf statement is interpreted as closing of outer double quote of awk.
ssh someserver 'cat /proc/*/status' | awk 'foo'
will remove any quoting issues compared tossh someserver "awk 'foo' /proc/*/status"
or similar (you don't need a loop either way btw).