If you've ever wanted to test to see what a command will do on Linux, without the end results, there's an app for that. A tool called maybe might become your best friend.
There are times when you know a command must be run, but you'd really like to test the action before execution. This could be on a production server, where running a command could have results that might negatively impact the server's ability to perform. When any systems administrator comes across such an instance, the impulse would be to turn to a test server, set up to mirror the production server.
But what if you don't have the luxury of such a test server? What do you do? You could turn to the likes of the maybe command. maybe is a piece of software (one that should be considered very much in the alpha stages—so tread carefully) that allows an administrator (or user, for that matter) to run a command and see what that command would do to the file system on the machine. When you issue a command with maybe, it will output the results of what running the actual command would do. Once you've looked at the possible outcome, you can then decide if you want to execute the command or not.
Let me walk you through the process of installing and using maybe. I'll be demonstrating on the Ubuntu Server 16.04 platform.
The maybe command depends upon pip for installation. In order to install pip, open up a terminal and issue the following command:
sudo apt-get install python-pip
When that command completes, you can then install maybe with the command:
pip install maybe
Once that completes, I recommend installing maybe using apt as well (otherwise the maybe command cannot be run with sudo). Run that installation like so:
sudo apt install maybe
And that's all you need to work with maybe. Let's use it.
SEE: Why Munich made the switch from Windows to Linux—and may be reversing course (TechRepublic)
The maybe tool is actually quite simple to use. By prepending maybe before any command, maybe will output the results of the run and ask if you want to actually move ahead with running the command or stop.
Here's an example. After you install pip, you will immediately be informed that pip is out of date. To upgrade pip, you issue the command pip install —upgrade pip. If you change that command to maybe pip install —upgrade pip, you will be presented with exactly what the command would do (Figure A).
Should you want to continue with the command, type y. If you don't like the looks of the output, type n and maybe will not execute the command. It's as simple as that.
If you need to test a command that requires sudo rights, use maybe like so:
sudo maybe apt update
I will mention this: Commands like sudo maybe apt upgrade will not work with maybe. I'm hoping this is just a matter of the tool being in alpha (otherwise maybe becomes far less useful).
Where maybe becomes very useful
On the upside, maybe is a great way to test installation scripts. Say, for instance, you've downloaded an installation script for a server platform and want to see what it will do before you actually run it. If the script is called install.sh, you could issue the command sudo maybe ./install.sh to see what happens (Figure B).
Once maybe runs the install script, you can then decide if you want to continue with the installation or not.
Far from perfect
The maybe tool isn't perfect—far from it, actually. However, there are instances (such as install scripts) were using maybe makes perfect sense. I'd recommend testing maybe on a non-production machine at first (so you can get to know what it can and cannot do). That may sound a bit redundant (for a tool designed to protect you from issuing a command that would negatively impact your server), but you will want to first make sure this tool is something you can use effectively.
It is my hopes the developer of maybe will continue work on this handy tool. Linux needs something exactly like this for administrators who second guess their command line fu.
- How to use the apropos command to easily remember other Linux commands (TechRepublic)
- How to enable Linux machines to resolve Windows hostnames (TechRepublic)
- How to parse the Linux last command to display specific logins (TechRepublic)
- How to prevent root login on your Linux servers (TechRepublic)
- Linus Torvalds on Linux, life, and bathrobes (ZDNet)