Skip to content

Instantly share code, notes, and snippets.

View qmaxquique's full-sized avatar

Enrique qmaxquique

View GitHub Profile
#!/usr/bin/env bash
# https://raymii.org/s/tutorials/IPSEC_vpn_with_CentOS_7.html#No_L2TP?
echo "This script is to be executed in the VPN server!!"
echo "Continue in 5 seconds..."
sleep 5
yum -y install strongswan
yum -y install haveged

Let's say you have a Bash shell script, and you need to run a series of operations on another system (such as via ssh). There are a couple of ways to do this.

First, you can stage a child script on the remote system, then call it, passing along appropriate parameters. The problem with this is you will need to manually keep the remote script updated whenever you change it -- could be a bit of a challenge when you have something to execute on a number of remote servers (i.e., you have a backup script running on a central host, and it needs to put remote databases in hot backup mode before backing them up).

Another option is to embed the commands you want to run remotely within the ssh command line. But then you run into issues with escaping special characters, quoting, etc. This is ok if you only have a couple commands to run, but if it is a complex piece of Bash code, it can get a bit unwieldy.

So, to solve this, you can use a technique called rpcsh -- rpc in shell script, as follows:

First, place th