Send command via ssh to another server

Hello,

i`m tryeing to execute loop on remote server and i have problems with syntax

my command is

ssh root@server "for i in /vz/private/*; do b=`ls -la $i/usr/bin/crontab | awk '{print $1}'`; echo $b; done"

with this command i`m tryeing to get all permissions of file /usr/bin/crontab
this file can be found in any subdirectory of directoryes in this folder /vz/private/

when i execute that command in remote server it works fine, but when i try to send loop via ssh to that remote server then i`m getting empty values

---------- Post updated at 04:33 AM ---------- Previous update was at 04:25 AM ----------

dont need it any more, i got it working with command:

ssh root@server "for i in /vz/private/*; do ls -la $i/usr/bin/crontab | awk '{print $1}'; done"

A more sensible approach, rather than trying to "make it work" as one-liner:

  1. put the working command into a script
  2. chmod +x the script file
  3. scp -p the script to the remote box
  4. ssh remoteserver '/path/to/script'

You now have a general model to do anything on the other side. You can automate: put steps 1-4 in a local script.