Visit Our UNIX and Linux User Community

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

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I execute local script on remote machine and include arguments?
# 1  
Old 09-03-2015
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

Last edited by manohar2013; 09-03-2015 at 01:23 PM..
# 2  
Old 09-03-2015
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/

Beware that stdin won't be available for keyboard input because it's occupied feeding a script into the remote server.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 09-03-2015
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

# 4  
Old 09-03-2015
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).
# 5  
Old 09-03-2015
the below code is getting accurate results...but Im unable to execute script..
ssh $username@$hostname ls -ltr /home/dell/work/BOP/testdir;

# 6  
Old 09-03-2015
Then the script is not on the local machine, it's on the remote one.
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 09-03-2015
ssh user@host /path/to/file arg

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

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute shell script on remote machine

I want to execute a shell script(set of commands) on remote machine and that script takes input from text file(local machine). Please refer below: ssh user@hostname 'bash -s'< ./ file.txt But i got the error file.txt doesn't exist. Can anyone help me on this. Content of ... (2 Replies)
Discussion started by: manishtri88
2 Replies

2. Shell Programming and Scripting

Help with fetching the data from remote machine from my jumpbox(local machine)

Team, Presently i am running a script from my local box(i.e jumpbox) to all the remote machines.Basically fetching basic queries like pwd,mkdir,touch etc and i am able to successfully fetch it from my local machine.But when i want to check certain database related queries like the dbstat... (20 Replies)
Discussion started by: whizkidash
20 Replies

3. Red Hat

iptables applied in local machine, can't ssh remote machine after chain changed to DROP

I want to SSH to Server from my machine, my ip was Source Destination was UP, with IP This is LAN Network there are 30 Machine's Connected to the network and working fine, I'm Playing around the local machine's because I need to apply the same rules in... (2 Replies)
Discussion started by: babinlonston
2 Replies

4. UNIX for Dummies Questions & Answers

Execute shell script in remote machine

Hi All, We have 2 servers A and B. B is having a sctipt called in path /home/dev/scripts. Now my requirement is i want to execute from server A. Kindly help me. (3 Replies)
Discussion started by: Girish19
3 Replies

5. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < However, when I try to pass arguments to it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

6. Shell Programming and Scripting

Execute a local script against a remote server

I am unable to run the below script against a remote server due to syntax error (then unexpected), but i am able to run it locally. Am i executing it correctly or is there any other way to execute it. ssh username@servernname ksh -s < scriptname #!/bin/ksh function record { ((end =... (5 Replies)
Discussion started by: NarayanaPrakash
5 Replies

7. IP Networking

Execute script located on a remote machine

So, is there way of automating this ? My ultimate goal is to run some cmd script in windows and it should connect to a remote unix host and run a script located on the remote unix host. I was wanting to achieve this by using WinSCP and Putty only. If possible let me know how and if not... (25 Replies)
Discussion started by: mohtashims
25 Replies

8. Red Hat

To find the LATEST file from a dir on REMOTE machine and SCP to local machine?

Hi All, URGENT - Please help me form a scipt for this: I need the LATEST file from a dir on REMOTE machine to be SCP'd to a dir on local machine. (and I need to execute this from local server) I know that the below cmd is used to find the LATEST file from a dir. But this command is not... (3 Replies)
Discussion started by: me_ub
3 Replies

9. Shell Programming and Scripting

Change user on remote machine and execute script!

Hi, I need to login into remote server and execute a shell script over there. As of now i am making use of ssh command ssh primUser@ sh / I am logging in as primUser but unless i change the user to root the script execution on the remote machine is not possible. ... (5 Replies)
Discussion started by: goutham4u
5 Replies

10. Shell Programming and Scripting

how to execute a script on remote machine

hi unix guru's i am new to unix shell programming. i found a trouble in executing a script(bali.ksh) which is available on serverA with username xyza, this script contains sqlplus command to retrive the data from the database available on other serverC. Now i need to run the above script... (4 Replies)
Discussion started by: balireddy_77
4 Replies

Featured Tech Videos