Host Script in the Cloud

OSX

Is there a way to host a script on a server? Specifically, the end user would pop in a terminal command or script that fetches text (a formatted script) from a server and runs that code on the local system.

I want to do this because I have a script that is constantly evolving and it would be nice to edit a source file on a server for updates without having to push out a new script every time.

I think it's worth mentioning this would be done behind a firewall.

Yes you can use wget to fetch the script from a server to the local system as long as your firewall will allow the local system to http:// (port 80) browse to the server in question.

wget http://yourserver.com/path/to/your/script.sh
if [[ -f script.sh ]] && [[ $(md5sum < /usr/local/bin/yourscript.sh) != $(md5sum < script.sh ]]
then
    cp /usr/local/bin/yourscript.sh /usr/local/bin/yourscript.old
    mv script.sh /usr/local/bin/yourscript.sh 
else
    rm -f script.sh
fi
1 Like

How about you pass an 'execution' script to the users, which does similar things like Chubler_XL suggested.
But basicly, it will just download your real script and execute it.

1 Like

Yes depending on how frequently you expect it to change. One could use a daily/hourly cron job to check for updates, or always fetch it and execute as you go.

I would be careful if the script is executed as root as it would be very easy for someone to attach and insert their own script into your system. Perhaps using https:// with a proper certificate would be wise.

1 Like

This said, you could also package it according to your package manager.

As in, TUI (Text User Interface) is actualy a bash based project, and since my linux is fedora, i have it packated as an rpm.
But regardless if its a script or not, if it needs updating on a frequent basis, a package might be more apropriate.

hth

1 Like

Thanks Sea and Chubler. So, wget would be cool but it would require everybody to procure wget, so I would like to stay within the normal scope of bash on OSX. I was thinking about using SSH and either a scp or rsync to grab the file.

With that being said. I was hoping to get your input on this:

Route 1: Distribute a script that simply ssh's into the server, pulls the script down to /tmp, executes, and removes from /tmp when finished.

Route 2: Distribute the up-to-date version of the script, use diff to check the local version with the server version, if there is a difference overwrite the local version with server version, execute.

Thoughts?

Depending on the script complexity, a simple ssh user@host cat script.sh | sh might be sufficient.

1 Like

It would be great if this worked; however, the script seems to get tripped on on a while loops that includes a 'read' command. It never prompts the user for input and just passes right over it to the next line.