ssh command in ksh script encounters permission error

I've created a script and copied it to another server and try to execute it at the same time but I'm getting a permission error.
I'm logged on as root and I gave the file 777 permission when I created it, but I can't run it remotely via ssh command because of permission issue.

Any ideas?

Thanks in advance.

#!/usr/bin/ksh
..
..
chmod 777 /usr/local/bin/${script_name}
scp /usr/local/bin/${script_name} ${servernames$iy]}://usr/local/bin/
ssh root@${servernames[$iy]} 'cd /usr/local/bin/userid/; ./${script_name}'
..
..

./myscript.ksh

Please type the userid
paultest

Please type the server name
bk02

root@bk02's password:
script2run.ksh 100% 72 0.1KB/s 00:00

root@bk02's password:
ksh: ./: 0403-006 Execute permission denied.

Ack! It's rare that a file needs 777 permissions, especially one that is owned by root. But if you want to keep the permissions, change the scp line to:

scp -p /usr/local/bin/${script_name} ${servernames$iy]}://usr/local/bin/

Permission was set to 700 but I changed it to 777 to make it work and it didn't.
cp -p option didn't work either.
Thanks.

Where in the script are you declaring ${script_name} ?

You didn't post the entire script, but by the message you are getting, it seems that ${script_name} is null and what the ssh command is trying to execute is just ./
BTW, you don't need to cd then execute. Just do

ssh hostname /usr/local/bin/script

Also, your scp command pretends to copy ${script_name} to /usr/local/bin, but your ssh command goes to /usr/local/bin/userid.

Thanks System Shock.
I'll try that.

Thanks System Shock. That worked. You're an expert!

One more question,

Is there anyway that I can reset user's password using ssh command?
ie. emulate passwd command with a default password of abc123 or even null value?

> ssh server1 pwdadm user1 < /dev/null
or
> ssh server1 passwd user1 < /dev/null

neither worked for me.. but you know what I mean... I couldn't emulate enter keys.

I know this method is not recommended, but I've got more than 40 servers, and I don't want to login to every server to reset passwords.

Thanks.