Posts

Showing posts from December, 2014

Talking with DigitalOcean from shell or JSON + bash = rcli

RESTful APIs with JSON are all over the software world.  SaaS, PaaS and other aS'es frequently expose HTTP endpoints that eat and breed JSON. They're fairly easy to work with by using almost any language, except when it comes to do something really simple from a shell script. Having extremely positive experience with JavaScript library Ramda that makes JSON processing very verbose, I'm now discovering new uses of it's command-line sister - Rcli: Ramda for Command line . DigitalOcean example Let's pretend we have a droplet in DigitalOcean and want to run a script on it. We're going to figure out droplet IP using API and run some script there via ssh. Sounds ideal for bash script. IP=`curl_get_droplet | \   R path droplets | \   R find where '{"name": "example.com"}' | \   R path networks.v4.0.ip_address ` ssh root@$IP 'bash -s' < script.sh For simplicity, I replaced exact curl command with curl_get_droplet func