Tag: linux

How to update Grafana from version 4 to version 5

Grafana is a wonderful tool to display time series ans a lot of different metrics
The project is in a very active development state , and new features are added constantly.

The version 5 is particularly desirable since a new layout engine for the dashboard has been developed, and is quite powerfull !

So to update your install of Grafana from 4 to 5 you need to launch several command with root or a privileged user.

The service should automaticly restart when the update is done , but check that it is running with :

service grafana-server status

You should see something like this

? grafana-server.service – Grafana instance
Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; disabled)
Active: active (running) since ven. 2018-04-20 17:47:41 CEST; 1 day 22h ago

Use the keyboard on a remote machine over SSH?

If you use a Linux box to display some infos in a public space , you might not have the possibility to connect a mouse and keyboard every time you need to click on the page.

For example, at work we use a TV to display some metrics with grafana,
Sometime, when we reboot the machine , the identification cookie will be outdated and the browser will land on the authentication page instead.
Since the machine has no keyboard and mousse attached this cause some issues , .
So I’ve used the tool xdotool that allow a privileged ssh user or a script to interact with the mouse and keyboard

An important step is to select the screen on witch you want to send mouses clicks and keystrokes.

After that lets say your screen is displaying a full-screen browser with a login page ,
By default the cursor is already in the login form.

for the example , the login/password are going to be admin/admin

you are now logged and you dashboard will display

Bash brace expansion. (to delete files)

In bash , it is common to have to do some action on a numéric serie of files , like deleting or renaming ,

Using brace expansion you will be able to générate a single line that will act on multiple targets ,

For our example , let’s think about a list of ten files

in the simple case where i want to delete the complete list of files, i just have to run de command,

The 10 files will be deleted, but , this is not practical if you want to keep the last file , and delete the other nine,

In that case we can use a usefull tool called brace expansion,

To delete the files 1 to 9 , i just have to run in my bash terminal!

This last one is extremely practical , I use it very often in a lot of different uses cases.

But in other cases , you may want to delete even on odd files , or one every three files,

This is also doable with braces expansions

InfluxDB insert multiples values at once using curl

If you have to insert multiples values in an influxdb database. You can use curl and insert the values one at the time.

But there is a better way like in this example

Let’s say you want to insert your tree loadaverage values in you influxdb database.

First put them into variables using these 3 lines.

Then using this curl line, insert them all at once in your influxdb database

BASH : Make a SQL query from bash

MySQL is a very convenient way to store data .
To use stored MySQL data in a BASH script you can use this simple command

this will display the result in you terminal without ASCII decorations.
if you need to use that data for something , you can store it in a var

BASH : IP validation 

if you have a list of ip to validate ,
you can use this little bash script ,
this will open your IP list ,
then test if all the 4 numbers that make a standard IP.are beeten 0 and 255

if the ip is valid then the script will return valid , else it will return : not valid

after execution , you will get the following result :

Bash : Delete some characters from a file with TR

in this little example of usage of the command tr
we want to clean a file so the values contained in it can be used
Example File

In my example i wish to only keep the value and deleting the character < and >

the tr command used with the -d (delete) option will allow you to delete the list of characters contained between the quotes.

You will obtain the following result

Re-apply .bashrc

After you made some changes on your .bashrc file (like creating some new aliases) You will notice that the changes are not applied upon the saving of the .bashrc file

After having saved the file , first insure you are in your home folder, by typing cd .

and to reapply your .bashrc config file , launch a :

after this you can test you alias right away , it should work