Monthly Archives: March 2020

Basic package deployment using Chocolatey

Ever wished to have a package manager on Windows? Using Chocolatey, you will be able to access either a common repository located online or your own private repo hosted on-premise. Using in addition to automated tools like Ansible, Chef, Puppet or even regular GPO, you will be able to manage your servers and workstations packages like a pro!

This document is just a basic showroom, we will explain how to deploy Chocolatey on your local machine, and run some commands. Later, I will probably update or explain how to manage a local repository.

Installing Chocolatey

It’s very simple, all you need is to open a Powershell v2 command prompt, with administration privilege though, then enter the following command:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

This will set the bypass the execution policy, to avoid being block by the restricted mode, then execute a script remotely downloaded from Chocolatey’s website. I would recommend you to download the script manually before, for checking both the website certificate and the script content.

Once it’s done and installed, restart the Powershell console and enter the following command to see if everything went well:

choco 

You should get something like that:

Chocolatey v0.10.15
Please run 'choco -?' or 'choco <command> -?' for help menu.

Basic commands

Inspect which repositories are set for the current installation:

choco sources

That will show you something like that:

Chocolatey v0.10.15
chocolatey - https://chocolatey.org/api/v2/ | Priority 0|Bypass Proxy - False|Self-Service - False|Admin Only - False.

Look for a specific packet, see the different version:

choco find vlc

Install the packet you just found:

choco install notepadplusplus

Uninstall a packet:

choco uninstall mpc-hc

Upgrade all the packages:

choco upgrade all

That’s all for now, I will update this topic later. However, you should have seen how easy it is to deploy packages now, and how great it is if you want to create scripts to ease a post server/workstation installation for example.

Desktop template

Here I drop the classic packages I usually install on my workstations, so I don’t need to remember everything.

choco install 7zip adobereader googlechrome greenshot notepadplusplus skype teamviewer treesizefree mpc-hc openssl putty nodejs git lavfilters mremoteng postman vscode wireshark anki discord libreoffice naps2 -y

Nagios, fix the Enable web commands error

I had to deploy a lot of dedicated Nagios application based on the 18.04 LTS Ubuntu edition, and doing so, on a fresh install, I was annoyed by the following error message, after login to the web portal:

Could not stat() command file '/usr/local/nagios/var/

To fix that, run the following set of commands

sudo service nagios3 stop
sudo dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw
sudo dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3
sudo service nagios3 start

Then, you should be good to go!

Chaining grep commands after tail -f

Sometimes, I need to filter out real-time logs on server which is not taking part of a log aggregation tool, such as Graylog or ELK.

Sometimes it’s also very convenient and quick to run a command and see live what’s going on.

To see any new line added to a log file, you should already know the tail function:

tail -f /var/log/mail.log

Unfortunately, you won’t be able to use this command with more that on command chained, for instance:

# The following command will work:
tail -f /var/log/mail.log | grep from=

# The one below won't show you an error, but won't display anything as well:
tail -f /var/log/mail.log | grep from= | grep me@domain.com

Some command, like grep, comes with a specific directive that can workaround this issue: –line-buffered

Not all tools have it though, for example, with cut you will have no dice. If only one command you would use is not providing a way to do that, use it at the end.

Let’s make a quick example, if I wan to use two greps command and a cut, I can do:

tail -f /var/log/mail.log | grep --line-buffered from= | grep --line-buffered -v -e "from=<>" -e "root" | cut -d ':' -f 4,5

This will show me the 4 and 5 fields of any new line added to mail.log, which contains the expression “from=”, filtering out any empty sender or root (“from=<>” and “root”). So I will get output like that one:

33FEA13B970: from=<user@domain.com>, size=467, nrcpt=1 (queue active)