What is the detailed problem description behind the phrase "it doesn't work" there?
If it is asking for passwords in the script but using keys in the direct shell then it is a matter of pointing the script to the keys and the key agent.
Code:
#!/bin/sh
echo SSH_AUTH_SOCK = $SSH_AUTH_SOCK;
for i in $(cat /some/folder/serverx.txt);
do
scp -i /path/to/some/key.rsa -P 22 /some/folder/test1.sh "admin@$i":/tmp/
done
exit 0;
Note the absence of -r when you copy a single file. Also note that -i may be needed to tell
scp which key to try. See "man ssh" and "man scp" and if your script gets fancier you might look at
sftp instead since that is actively developed and
scp isn't and won't be.
scp is just a replacement for the old, insecure
rcp and that is all.
Also, try checking the environment variable $SSH_AUTH_SOCK first to see if it is available to your script.
Also how are you invoking the script? It is in the same shell or in a different environment completely?