Package: rucksack
A place to store your useful one-linersOverviewRucksack is an interactive command runner that provides useful auto-completion capabilities for those hard to remember one-liners that we all have. It provides a way for you to run your one-liners againt remote systems, complete with any needed arguments (templated out via Jinja2), without having to remember them.It was inspired by thatuseful_stuff.txtfile that every SysAdmin has on their desktop. You know the one: you come up with a clever one-liner, and you throw it in there so that you can reuse it someday.Rucksack allows you to store your one-liners (and their potential arguments) in aYAML file. You can then connect to a remote host (or localhost) and run those one-liners from one easy place. No more copying and pasting from auseful_stuff.txtfile!Want to learn more? Head on over to thetutorialfor more examples and to get started!Warning:Rucksack is a very new project and is under heavy development. Things may change. I think I've got the config file syntax nailed down, but this is still an early project. Please file an issue if you come across a bug.InstallingRucksack is available on PyPi and can be installed viapip:pip install --user rucksackThe installation will add theruckcommand to your path.UsageRucksack has a help page. Simply runruck -hto see all options.In general, you simply need to specify--host ${hostname}so that Rucksack can connect to a remote host. If you specifylocalhostor127.0.0.1, Rucksack will not attempt to connect via SSH and will simply shell out local commands.Once you launch Rucksack, you will be taken to a prompt. From there, you can run any commands you have defined in your configuration. To quit, simply enter thequitcommand.ConfiguringRucksack uses a simple YAML configuration file (or multiple YAML files) for its configuration. The easiest way to become acquainted with the configuration file is to try out thetutorial.Config File LocationRucksack is configured via one or more YAML files. You can specify a configuration file or directory at the command line, or you can let Rucksack search for one in the following orderArucksack.ymlorrucksack.yamlin the local directoryAny.ymlor.yamlfiles in your home directory at~/.config/(e.g.,/home/tony/.config/rucksack/config.yml)Any.ymlor.yamlfiles in/etc/rucksack/(e.g.,/etc/rucksack/config.yml)An/etc/rucksack.ymlor/etc/rucksack.yamlfileRucksack will process the above listin orderand will stop once it has loaded one or more config files from those locations.Config File SyntaxThe best way to get up and running with Rucksack configuration is to follow thetutorial. If you're interested in the logistics of a Rucksack config, then feel free to read on. However, reading the tutorial isstrongly encouraged, as it will take you through concrete examples.For the purposes ofSemantic Versioning, the config file format is the "public API."The basic unit of configuration in Rucksack is a YAML dictionary with acommandkey:get-uptime:command:uptimeThese dictionaries can be nested, which aids in creating more sensible auto-completions:system:basic-info:get-uptime:command:uptimeA command can have 0 or moreargs(arguments), and those arguments can optionally be mandatory. Arguments are rendered usingJinja templates.tail-log:command:"tail{{log_file}}"args:-log_file:mandatory:TrueAn argument can specify values to the user, and can even have a default value:tail-log:command:"tail{{log_file}}"args:-log_file:mandatory:Truedefault:/var/log/syslogvalues:-/var/log/syslog-/var/log/kern.log-/var/log/auth.logSometimes, you only want to render an argument if the user specifies a value. For example: you don't want to render a command-line flag if the user didn't provide any value for it. This can be done with anarg_stringkey for the argument. In the example below, thenum_linesargument only appends-n {{ num_lines }}to the command if the user specifies a value fornum_lines.tail-log:command:"tail{{log_file}}"args:-num_lines:arg_string:-n {{ num_lines }}-log_file:mandatory:Truedefault:/var/log/syslogvalues:-/var/log/syslog-/var/log/kern.log-/var/log/auth.logFinally, argument values can be dynamically interpolated as the result of other commands. The example below provides a list oflog_files for the user to choose from by executing afindcommand in/var/log/nginx. Be aware that command output is cached, so this might not be appropriate for values that change often.nginx:get-top-5-ips:command:"sudocat{{log_file}}2>/dev/null|cut-f1-d''|sort|uniq-c|sort-hr|head-n5"args:-log_file:mandatory:Truefrom_command:"sudofind/var/log/nginx-name'*access.log*'|grep-v'.gz'"Caveats and Known IssuesThere are currently a few caveats to using Rucksack (please file an issue if you find more):Password entry via asudoprompt isn't really supported. It will work, but it won't be pretty. It's expected that the remote user has permissions to execute any commands used by Rucksack (or that they can use passwordlesssudo).Thefrom_commanddirective is naive, and it will ignore any errors. For example: imagine that thefindcommand in the above config is broken. Rucksack will simply ignore this and won't present any values to the user for the auto-completionConfig file validation isn't currently implemented, so you may get unexpected results (such as exceptions thrown when exiting) if your config file is broken.Config file parsing, auto-completion, and command rendering almost certainly are not as efficient as they could be (lots of looping over dictionary keys or arrays). Optimizations will come with time.Tests and test logic could use a lot of cleanup and reworkCreditsThanks to my very talented wife,Megan Critelli, who designed the Rucksack logo. She does commissions and sells prints.Rucksack stands on the shoulders of some giant projects that made it easy to construct. Special thanks to the following projects for such great Python tools. If you enjoy Rucksack, please consider supporting these projects.Python Prompt ToolkitFabric