Let’s Start SaaSGlue — Part 2

Bart Wood
6 min readJul 16, 2021

Goal: Download an agent and run a script.

Prerequisites: Part 1 - Setting up an account.

When you use SaaSGlue, the core thing you’ll do is run scripts. The scripts can be written in pretty much any language you want. There’s a lot more to SaaSGlue than just running scripts but to get started we will run a simple script.

To run a script, you first have to download an agent.

We have SaaSGlue agents customized for Windows, Linux and Mac. These instructions will be Mac specific for now but I’ll try to update this article later (July 2021) to include Windows or Linux instructions as well.

Download an agent by clicking “Download Agent”, click what Operating System the agent will run on (Mac in this example) and click “download the Mac agent”.

When you download the agent the file will be named “sg-agent-launcher.gz”. Open the sg-agent-launcher.gz file in Finder (probably in your “Downloads” directory) and double click the file to unzip it. The unzipped file “sg-agent-launcher” is the actual SaaSGlue agent.

You can copy the agent executable file “sg-agent-launcher” anywhere you’d like (as long as you have folder permissions).

To run the agent, we need to make sure we have permissions to run it. To keep things simple, it’s probably easiest to leave the agent in your “Downloads” directory because you have the correct permissions there.

Open a terminal (MacKey + Space and type terminal) and navigate to your downloads directory (cd ~/downloads). Change the permissions on the Agent by typing “chmod 711 sg-agent-launcher”.

If we tried to run the agent at this point it won’t work. We need to set up custom credentials to run the agent that are specific to our team (probably a team of one to start out with).

Let’s create the agent configuration file. The agent configuration should exist in the same directory as the agent (~/downloads in this example). The file should be named “sg.cfg” and it should look like this:

{
"SG_ACCESS_KEY_ID": "the_key_id",
"SG_ACCESS_KEY_SECRET": "the_secret"
}

Now let’s use the SaaSGlue app to get “the_key_id” and “the_secret” values.

Click the link at the top right of the SaaSGlue console app (it will be your user name) and click the menu link “Access Keys”. The “Agent Access Keys” tab should be selected by default.

Click the button “Create Agent Access Key” at the bottom of the window and give your new key a description. Click “Create Access Key”

Give your key a description and click the “Create Access Key” button.

Copy the secret value (6cbb79… in this example) and replace “the_secret” with this value in the sg.cfg config file.

Click the “I Have Copied The Secret” button. If you didn’t copy it, no problem. Just create another key with a different description but make sure to copy the secret into your sg.cfg file before clicking “I Have Copied The Secret”.

You should see the “Access Key ID” in the API Access Keys screen now.

Replace the “the_key_id” value in the sg.cfg file with the Access Key ID value shown in the API Access Keys screen.

In our example, our sg.cfg file would now look like this:

{
"SG_ACCESS_KEY_ID": "MYA5ZQA7CGC7XGAWEVJV",
"SG_ACCESS_KEY_SECRET": "6cbb7938956xxxxxxxxxxxxxxxxxxxx"
}

Now that the sg.cfg file has been created with a valid key id and secret, the agent can securely connect to the SaaSGlue cloud.

To run the agent, type this command from the terminal window. “./sg-agent-launcher”

You might see a security warning from MacOS. If you do, you’ll need to open your mac preferences “Security & Privacy” and give the SaaSGlue agent permissions to run.

Now that the agent is running, you should be able to see the agent’s status in the SaaSGlue console. Click the “Agents” menu and you should see your new agent.

Initially your agent will be the same name as your machine name and it might be hard to recognize. You can select the agent and rename it in this screen if you’d like. The important thing is that the agent is running with a green status of “Active”. Agents heart beat frequently to let the SaaSGlue cloud know they are open for business.

There are other ways to keep agents alive and running besides manually from the command line but this is good enough for now.

Now let’s run our first script on the agent. Click the “Scripts” link in the top menu and click the “Create Script” button.

Give the script a name and select a script type of “Shell” and click “Create new script”.

You can eventually run many other languages but to keep things simple, I’ve picked a language that I know can run on any Mac machine. There are pretty easy ways to automatically ensure the languages you’d like to use exist on the machines where an agent is running but we’ll keep it simple for now.

After you’ve clicked “Create new script” you should notice that you’re no longer looking at the “Scripts” page but you’re now on the “Console” page.

The “Console” is a place where you can create and test your scripts quickly. Most of the real work is eventually done in the “Designer” but when you’re first getting started you’ll spend some time testing scripts in the Console.

You’ll notice that your newly created script is selected in the top selector box.

Let’s make our first shell script easy. Type in the following code into the script editor:

pwd
echo "My first script!!!"

The “pwd” command is just going to print the working directory and the echo command is going to put “My first script!!!” into the standard out.

To run this script, scroll down to the bottom of the Console and you’ll see the following options.

You can ignore most of these options for now. For the “Target Agent(s)” option select “A Specific Agent” and in the Target Agent option you should see your new agent as a choice and it should be colored green meaning it is active.

Once you’ve selected your agent, click the “Run Script” button. The console window will change to show live output of the script running.

We can see where the script ran, if it succeeded and things like standard error and standard out. The standard out tail will be shown as well (3 recent lines). We can see our little shells output. The results of the “pwd” command “/Users/bartwood/Downloads/” as well as our test message “My first script”.

Nice! Now you can run scripts remotely via SaaSGlue!

In later articles we’ll do much more complicated things.

Now, previously I said that you need an agent to run a SaaSGlue script. Not really. In some situations, you might want to skip the agent and run scripts in AWS Lambda. I’ll go through that as well in another article

--

--

Bart Wood
0 Followers

SaasGlue Founder, Programmer, Guitar Hero Wannabe