:::: MENU ::::

Monthly Archives / January 2015

  • Jan 22 / 2015
  • 0
Linux

Add a function in shell on Linux (make dmesg timestamps human readable)

You want to add a specific function on your shell which is not available in standard functions and you would like to be able to call it anywhere you want without the need to specify the script location? That’s quite easy to do, with some simple tricks ­čśë !

We will here work with a simple example of a useful function:

When you are calling the dmesg command, you got a timestamp which is not human readable and it can be hard to align these logs with the logs of another application running on the server for example. We will create a function called dmesghr (for dmesg human readable) that will allow us to call exactly the same than the dmesg command but with a timestamp human readable.

First of all, we will create our function under our profile at the end of file ~/.bashrc after all the already existing declarations:

Once this done, we will reload the profile file and export our new function so we can use it anywhere:

Right now, we can call it directly from our shell and use it as a standard function:

  • Jan 12 / 2015
  • 0
Linux, Python

Create an interactive command-line menu using Python

It can be necessary to create a simple interactive menu on CLI (Command-Line Interface) using Python to allow users to make some choices while executing a script/program. As there is no standard library for this in Python, you will have to adapt it by yourself.

Here is a very simple example of how to do this. Feel free to modify, update and improve it as depending on your needs and your expectations ­čśë !

Question ? Contact