473,394 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Run Local Script On Remote System via SSH

I have a script in my system. I want to run this script on the remote system which has SSH connection.
May 7 '20 #1
2 3690
It is very easy just put the script file path after the ssh command like below.
ssh ismail@192.168.142.144 'bash -s' < cat myscript.sh
May 8 '20 #2
You were pretty close with your example. It works just fine when you use it with arguments such as these.

Sample script:

$ more ex.bash
#!/bin/bash

echo $1 $2
Example that works:

$ ssh serverA "bash -s" < ./ex.bash "hi" "bye"
hi bye
But it fails for these types of arguments:

$ ssh serverA "bash -s" < ./ex.bash "--time" "bye"
bash: --: invalid option
...
What's going on?
The problem you're encountering is that the argument, -time, or --time in my example, is being interpreted as a switch to bash -s. You can pacify bash by terminating it from taking any of the remaining command line arguments for itself using the -- argument.

Like this:

$ ssh root@remoteServer "bash -s" -- < /var/www/html/ops1/sysMole -time Aug 18 18
Examples
#1:

$ ssh serverA "bash -s" -- < ./ex.bash "-time" "bye"
-time bye
#2:

$ ssh serverA "bash -s" -- < ./ex.bash "--time" "bye"
--time bye
#3:

$ ssh serverA "bash -s" -- < ./ex.bash --time "bye"
--time bye
#4:

$ ssh < ./ex.bash serverA "bash -s -- --time bye"
--time bye
NOTE: Just to make it clear that wherever the redirection appears on the command line makes no difference, because ssh calls a remote shell with the concatenation of its arguments anyway, quoting doesn't make much difference, except when you need quoting on the remote shell like in example #4:

$ ssh < ./ex.bash serverA "bash -s -- '<--time bye>' '<end>'"
<--time bye> <end>
May 9 '20 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: steve | last post by:
Hi, I finally figured out the best way to synch local and remote script folders, containing many php script files. What I used to do before was try to ftp all the changed files, etc. which was...
4
by: hokieghal99 | last post by:
This may not be possible, but I thought I'd ask anyway. Could I get the below code to run on a Python server where other machines would connect to it (say thru the Web) and get details of *their*...
1
by: John Puopolo | last post by:
All: I am writing a "net send" like application. The application runs on each person's PC, waiting for messages. Let's suppose "Joe" is logged in to 2 PCs, A and B. I would like to enter...
2
by: Yoshitha | last post by:
Hi All I need to develop c#.net application in which i need to access remote system from local system and can work on that remote system from local system. how such type of applications can...
1
by: joerozario | last post by:
how to start process at the remote system? Actully i used WMI to start process at the remote system. the process is created, and shown in the task bar (process) but i am unable see the started...
6
by: NetworkElf | last post by:
I am trying to write a little utility and it needs to check the startup type of a given service on a remote machine and, if it is disabled, set it to manual. I have found out how to do this on the...
1
by: joerozario | last post by:
Dear friends, I have Created a windows Service in .net 2005 to find the WMI Classes that are available in a system. When I invoke this windows service through a web site I could get all the...
3
by: almurph | last post by:
Hi everyone, Hope you can help me with this one. We are doing a batch process on both a local server and remote. By local I mean the db server is on the same box and by remote I mean the db...
12
by: =?Utf-8?B?YXVsZGg=?= | last post by:
i current have a way to read both local and remote machines registry keys and create a textual view (.txt output). i now looking for ways to do export of local and remote mahcine registry keys...
3
by: sakthikumarb | last post by:
Hi.. In local system, under universal serial bus controllers in Device manager.We can enable and disable the particular USB port. How can we do the enable and disable the particular USB port in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.