How can I execute local script on remote machine and include arguments?

I have a script in local server
cd /home/dell/work/BOP/testdir
./processchk po (here processchk is a script & po is passed as an argument)

Now I want to execute this script from remote server

ssh $username@$hostname "cd /home/dell/work/BOP/testdir; ./processchk po"

But Its getting error
ksh: ./processchk: cannot execute

Getting what error?

If the folder /home/dell/work/BOP/testdir/ doesn't exist on the remote server, cd /home/dell/work/BOP/testdir/ won't work on the remote server.

If the file processchk doesn't exist on the remote server. ./processchk won't work on the remote server.

To feed it into the remote end, you must tell the shell to feed it into the remote end.

ssh username@host exec /bin/sh -s arg1 arg2 arg3 < /path/to/script.sh

Beware that stdin won't be available for keyboard input because it's occupied feeding a script into the remote server.

1 Like

According to your suggestion, I have to pass only one arg for my script, so I used the below code

ssh $username@$hostname exec /bin/sh -s po < /home/dell/work/BOP/testdir/processchk

OUTPUt i got is

bash: /home/dell/work/BOP/testdir/processchk: No such file or directory

It means what it says: No such file or directory. Double-check that it's really where you think it is on your local server, and that you didn't somehow add carriage returns to your code (happens if you edit scripts with MS Notepad, etc).

the below code is getting accurate results...but Im unable to execute script..

ssh $username@$hostname ls -ltr /home/dell/work/BOP/testdir;

Then the script is not on the local machine, it's on the remote one.

1 Like
ssh user@host /path/to/file arg

If that doesn't work, there's something wrong with the file's contents or permissions.

Its working with the below command

ssh $username@$hostname "cd /home/dell/work/BOP/testdir; ./processchk po"

---------- Post updated at 11:01 ---------- Previous update was at 10:57 ----------

Success
Below code is working perfect...can you plz suggest any alternate code

ssh $username@$hostname "cd /home/dell/work/BOP/testdir; ./processchk po"

---------- Post updated at 11:03 ---------- Previous update was at 11:01 ----------

Thanks Corona688, Your suggestions helped me out & rectified me... where I went wrong

That is character-for-character identical with everything you tried before. What did you do differently?

Do you still need alternate code, now that it's "working perfectly"?

NOw Its working perfect..