Fabric and Reoccurring Tasks

So you have a handful of commands you execute weekly on multiple Linux servers.  You run these commands by opening a SSH tool like Putty, logging into the server, and then executing the commands.

Example commands:

  • ls /tmp/dropfolder
  • tail -10 /tmp/dropfolder/log1

With Fabric, you can bundle these commands and many others in a Fabric command file call fabfile.py.  Below is an example fabfile.py file containing just 1 task that will run (fabric.operations.run) the commands above.

from fabric.api import run

def dailycommands():
     run ("ls /tmp/dropfolder")
     run("tail -10 /tmp/dropfolder/log1")

You can then execute this file via the command line on 1 or multiple hosts with ease.

Example command:

  • fab -f fabfile.py -H host1,host2,host3 dailycommands

There are many many other things you can do with Fabric, so give it a try!

logo.png