@DennisWilliamson you mean especially point 3 ? as i have some trouble executing ssh someuser@somehost < $TEST inside shell script? And <<< as suggested in one answer also doesn't work...
–
DaywalkerAug 23 '13 at 19:22

You've changed the meaning of the code. In your solution, date executes locally rather than remotely. That defeats the purpose, which was to assemble a string of commands to run remotely.
–
200_successAug 23 '13 at 15:02

There are appropriate and inappropriate uses of eval. Please elaborate why eval is discouraged.
–
200_successAug 23 '13 at 15:04

1

I've updated my answer to add another example of how you can use commands remotely. @200_success for pesimists like you. mywiki.wooledge.org/BashFAQ/048. By the way, read this page. It's a life saving wiki.
–
val0x00ffAug 23 '13 at 15:10

@val0x00ff I just updated my Post. How do you mean I should solve it to be "correct"?
–
DaywalkerAug 23 '13 at 18:10

@Daywalker the TEST variable should be TEST=$(date; hostname -A; uname -a). Execute it as ssh rsync@example.com bash <<< "$(printf 'echo %q' "$TEST")" This will work. you just have to copy and paste. NOTE: Don't use CAPITALIZED variable names. Use proper variable names so you can distinguish one from another and lowercase. Only environment variables like "PATH", "HOME", etc... are capitalized.
–
val0x00ffAug 23 '13 at 19:53

$ help eval
eval: eval [arg ...]
Execute arguments as a shell command.
Combine ARGs into a single string, use the result as input to the shell,
and execute the resulting commands.
Exit Status:
Returns exit status of command or success if command is null.

There is no reason to compose such a long string of commands to run via SSH. Just make a permanent script on the remote host called /usr/local/sbin/rotate_backups and call it with ssh $USER@$HOST 'sudo /usr/local/sbin/rotate_backups'.

If you were asking this on the "Unix & Linux" StackExchange, then this could be an interesting question. However, as a System Administrator, your goals should be maintainability and security. If you are having trouble understanding your script, your colleagues and successors will curse you.

Thanks for the response, but I understanding the script is not the problem. In fact Security an manageability IS one goal t archive. I know its not one of the best scripts, but thats why I'm here ;) I just thought of to create just one script, which could be easily ported to other/new hosts. Maybe you are right an I should over think the concept. So you mean that I should create script and call it with all necessary variables like $DATASTORE_NAME and $MAX_SNAPSHOTS would also be ok, now as I think of it. Any other suggestion why this would be good/bad?
–
DaywalkerAug 23 '13 at 18:50

IS working on the command line directly, but not inside a script. remote_cmd="(/usr/bin/ssh $BACKUP_USER@$HOST_TO $RENAME_STRING)" and in the next line "${remote_cmd[@]}" I get a "Bad substitution" Error for the last line... (so eval is still in use...)
–
DaywalkerAug 24 '13 at 5:37

@Daywalker: Don't put quotes around the parentheses in the assignment. That prevents the array from being created. You should put them around the variables, though: remote_cmd=(/usr/bin/ssh "$BACKUP_USER@$HOST_TO" "$RENAME_STRING")
–
Dennis WilliamsonAug 24 '13 at 5:50

Now i get a Syntax error: "(" unexpected (expecting "fi") on your line remote_cmd=(/usr/bin/ssh "$BACKUP_USER@$HOST_TO" "$RENAME_STRING")
–
DaywalkerAug 24 '13 at 6:17

@Daywalker: If you have a space after the equal sign, it shouldn't be there.
–
Dennis WilliamsonAug 24 '13 at 11:18

No there is no space. This is somethign I would have recognized. (I updated my original post to show you what i have done
–
DaywalkerAug 24 '13 at 14:58