📜 ⬆️ ⬇️

How to find out what the program for Linux will do without actually doing it?

Have you ever wanted to know what actions the Linux team will perform, even before calling this command? Suppose you are an experienced user, and you know how many commands behave. But even you cannot know how everything works. Of course, the Explainshell web service can provide some help in finding out details about commands. To do this, you will need to copy and paste the command that interests you there, after which you will find a detailed description of how each part of it works. However, this is not our method. Thanks to the tool, which we now tell, to find out exactly how a certain program works, you can directly from the command line.



Meet the maybe utility - a simple tool that allows you to explore commands and find out, in all details, exactly how they will interact with the computer's file system during their actual use. At the same time, the program or team under investigation, in the test mode, has no effect on the system. You yourself, having read the report on it, decide whether to run it for real or not.

How does maybe?


The developer of the program tells the following about it: “Maybe performs processes under the control of ptrace , using the python-ptrace library. When a program intercepts a system call that causes changes in the file system, it writes the call to the log, then modifies the processor registers to redirect the call to an invalid system call ID (that is, essentially turning the call into an empty operation) . Further, it sets the value that this empty operation returns, so that it indicates the successful completion of the original call. As a result, the process is confident that everything that he is trying to do really happens, while in reality nothing happens. ”
')
It is worth noting here that great care should be taken when using maybe in any systems whose failure can lead to serious consequences. The fact is that this utility still blocks not very many system calls, as a result, its use can lead to computer malfunctions.

Installation maybe


Before installing maybe check if pip package manager is installed on your system. If this is not the case, below are the commands for installing pip on various Linux distributions.

In Arch Linux and other systems based on this distribution, such as Antergos and Manjaro Linux, you can install pip like this:

 sudo pacman -S python-pip 

The following sequence of commands will help you in RHEL and CentOS:

 sudo yum install epel-release sudo yum install python-pip 

In Fedora, you can do this:

 sudo dnf install epel-release sudo dnf install python-p 

Here is the appropriate command for Debian, Ubuntu and Linux Mint:

 sudo apt-get install python-pip 

In SUSE and OpenSUSE, use the following command:

 sudo zypper install python-pip 

After installing pip install maybe :

 sudo pip install maybe 

Working with maybe


It is very easy to use maybe . Just add maybe in front of the team you want to explore. Here's what it looks like:

 $ maybe rm -r ostechnix/ 

As you can see, I am going to delete the ostechnix folder and I want to know what will happen on my system if the above command is executed. This is what maybe says:

 maybe has prevented rm -r ostechnix/ from performing 5 file system operations: delete /home/sk/inboxer-0.4.0-x86_64.AppImage delete /home/sk/Docker.pdf delete /home/sk/Idhayathai Oru Nodi.mp3 delete /home/sk/dThmLbB334_1398236878432.jpg delete /home/sk/ostechnix Do you want to rerun rm -r ostechnix/ and permit these operations? [y/N] y 



It turned out that the rm -r ostechnix/ would perform 5 operations with the file system, as reported by maybe . Now I can decide whether I need to perform these operations or not. To me, this is simply a wonderful opportunity.

Here is another example. I want to install Inboxer - a desktop client for Gmail. Here’s how to figure out the appropriate operation using maybe :

 $ maybe ./inboxer-0.4.0-x86_64.AppImage fuse: bad mount point `/tmp/.mount_inboxemDzuGV': No such file or directory squashfuse 0.1.100 (c) 2012 Dave Vasilevsky Usage: /home/sk/Downloads/inboxer-0.4.0-x86_64.AppImage [options] ARCHIVE MOUNTPOINT FUSE options: -d -o debug enable debug output (implies -f) -f foreground operation -s disable multi-threaded operation open dir error: No such file or directory maybe has prevented ./inboxer-0.4.0-x86_64.AppImage from performing 1 file system operations: create directory /tmp/.mount_inboxemDzuGV Do you want to rerun ./inboxer-0.4.0-x86_64.AppImage and permit these operations? [y/N] 

If during the investigation of a certain command it is not possible to detect operations with the file system, maybe will display something similar to this:

 $ maybe sudo pacman -Syu sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges? 

Then I tried to investigate the update command of my Arch Linux, and maybe did not find any operations with the file system and did not display any messages about such operations.

Results


As you can see, everything is simple and clear. I really liked the maybe team, this is exactly what I've been looking for for a while. Now I can find out without too much difficulty what the team or program will do before it actually starts. I hope, maybe will be useful to you.

Dear readers! What usage scenarios maybe you see? The article mentions that maybe is a utility that is not yet completely ready for use on critical systems. Do you know something similar, but suitable for running on such systems?

Source: https://habr.com/ru/post/344210/


All Articles