shell scripting problems involving operations with remote machine

Hi,
i have been developing a shell script to transfer a set of files from one ubuntu system to another.

Task: while executing the script the files ( ls, dir, cat) in the source machine should transfer to destination machine(at /home/mac/mac/bin)

While the script is executed once again, It should create a backup file( bacup_date_time) and move all the old files in destination machine(at /home/mac/mac/bin) ti this backup file.

Here is the code i tried with,

ssh mac@192.168.3.247

filename=bacup_`date +%b_%d_%Y_%H_%M_%S`

mkdir /home/mac/mac/bin/$filename

cp /home/mac/mac/bin/*.bin /home/mac/mac/bin/$filename

scp /bin/ls /bin/dir /bin/cat mac@192.168.3.247:/home/mac/mac/bin

exit

My problem is I am able to run this script, but the backup files are not created.

I can see the files getting transfered, but I am not able to make a new backup directory and also copy the old files in remote machine.

please help me on this.
Thanks in advance:(

---------- Post updated at 12:54 PM ---------- Previous update was at 12:05 PM ----------

Don't mind, I got self help and the problem is solved by adding "here document" concept :smiley:

filename=bacup_`date +%b_%d_%Y_%H_%M_%S`

ssh mac@192.168.3.247 <<EOT

mkdir /home/mac/mac/bin/$filename

cp /home/mac/mac/bin/ls /home/mac/mac/bin/$filename
cp /home/mac/mac/bin/dir /home/mac/mac/bin/$filename
cp /home/mac/mac/bin/cat /home/mac/mac/bin/$filename



EOT
scp /bin/ls /bin/dir /bin/cat mac@192.168.3.247:/home/mac/mac/bin
exit