The test.sh script is most likely expecting something from stdin sort of like when you place ssh in a loop. e.g.
works but the following does not.
server2" | while read x;do ssh $x "ls";done
However, if you pass null in stdin for ssh then it works.
server2" | while read x;do ssh $x "ls" < /dev/null;done
See also -n option in ssh man page.
Unless you give more details about your script (such as the source) it is unlikely anybody can help you debug it. Also, you have a bit of redundant variable setting there. Why not just use while read DEVICE if you want to set the $DEVICE variable? There are more improvements that can be made but I'll leave you with that.