First, I would suggest using ssh only once. In other words, put your management script on the remote machine, then use ssh to execute that script. You can get the script there by using ftp, scp, or whatever. Then all you would do is:
ssh 10.10.10.10 management_script
If that's not an option and you
must execute the commands like the script you have above, then i would change it to something like this:
Code:
#!/bin/bash
old_ifs=${IFS}
IFS=$'\n'
cat command.file | while read cmd ; do
ssh 10.10.10.10 ${cmd}
done
IFS=${old_ifs}
exit 0
I honestly don't know whether you can redirect input like you had originally. I've always done it this way and it works. So what's the business about IFS? IFS stands for Input Field Separator (or something like that). It's default value splits lines of input into "words" by looking for spaces. This is bad if your commands have any spaces in them. For instance, a simple command such as
touch lock_file would be split, and two ssh command would be executed:
ssh 10.10.10.10 touch and
ssh 10.10.10.10 lock_file (which is clearly not what you want). The script saves the original IFS value, replaces it with a newline (so that a full line of text from the command.file will be treated as a single entry), and then restores the original value after the loop (in case you might add something to the script later).
Unfortunately, I don't have an environment to test this on (I only have one machine). So I can't say with 100% certainty it would work.