You need to pass to ssh the commands to be executed remotely as one string:
ssh 192.9.202.44 "tar tjf '/home/adup/mybackup.tar.bz2' | sort | grep -v '/\$' |( while read filename; do md5=\$(tar xjOf '/home/adup/mybackup.tar.bz2' \$filename | md5sum | awk '{print $1}'); echo "\$md5 \$filename"; done)"
Also, make sure characters like $
, which are interpreted by the local shell, are quoted.
The longer the script gets, the easier to make a mistake doing all this quoting. It can be easier to write a 'normal' shell script, copy it to the remote host with scp
, and then execute with ssh
.