Ninja Nichols

The discipline of programming

OCS Inventory (Where do I put cacert.pem?)

OCS Inventory is an inventory management system that can keep track of the machines connected to the network. It also features a package deployment system that can be used to run commands, install programs or copy files to the machines in the network.

There are a number of guides out there on how to set up the deployment system, but the problem I had is that they all tell you to copy your cacert.pem file in the “OCS Inventory Agent installation directory”. I thought that should be /etc/ocsinventory-agent/ but it’s not.

The directory where you should put it actually depends on the hostname of the OCS Inventory Server. Lets assume that my server is called “jones” and that I would access the control panel at http://jones/ocsreports. Then the location where I should copy the cacert.pem file on the computers running the OCS Agent would be /var/lib/ocsinventory-agent/http:__jones_ocsinventory/cacert.pem".

Multiple copies of program in “Open With” dialog

Why are there 20 copies of Photoshop?!

Sometimes duplicate copies of the same program seem to mysteriously show up in the “Open With” dialog. The problem seems to be worse for Windows programs installed with Wine.

The reason there are so many duplicate entries in the “Open With” dialog is due to the way file associates are handled in Wine. Every time a new program is installed in Windows, it has the opportunity to register itself as the handler program for a particular file type. This behavior is also present in Wine.

Each file handler is stored as a .desktop file in ~/.local/share/applications.

Sometimes though, Wine will create a new entry for each and every file type associated with a program. Take MS Excel for example, I have a distinct entry for .xls, .xlsx, .xlsm, .xltm, and .xlsb. These are just for Microsoft’s own variants of their Excel spreadsheet format and each one creates a new entry in the Open With dialog!

At this point, there are two options.

  1. Try to combine several entries together by allowing each one to handle several file types. This is accomplished by editing the “MimeType=” line in the .desktop file. The general format is “MimeType=catagory1/type1; catagory2/type2;” where “catagory1/type1” is something like “text/csv”.
  2. The above method seemed like too much work, so I opted for the second choice. Copy all the file type entries that you don’t need to another directory. I moved all but the essential entires to ~/.local/share/applications-old.

After a little cleaning up my “Open With” dialog looks much better.

How much power is your laptop using?

Products like Kill-A-Watt show how much power appliances are using. It’s good way to measure your computer’s power consumption — when it’s plugged in. But what if I want to know how much power my laptop is using when I’m not plugged in?

Turns out it’s fairly easy to get battery info. Running cat /proc/acpi/battery/BAT0/state should return the current discharge rate and total battery capacity.

The trouble is that the “current rate” field sometimes switches between mW and mA. I have no idea why this is the case. Oh well, we can easily convert mA to mW with the formula: $latex watts = amps times volts $.

The end result is this conky friendly bash script:

#!/usr/bin/env bash
# Print the current power consumption in watts.
# The script pulls the power consumption info
# from /proc/acpi/battery/BAT0/state
# Usage: [battery_num]
# Add to conky:
# ${execi 10 ~/conkyscripts/ 0}

# Default is BAT0
if [ $1 ]; then

# Sometimes the "present rate" is returned in milliwatts,
# but sometimes it is in milliamps. If it’s in milliwatts,
# we just convert to watts and return. Otherwise we
# convert to watts with the formula:
# Watts = Amps * Volts

UNIT=`cat /proc/acpi/battery/BAT$BATTERY/state |
grep "present rate:" | awk ‘{ print $(NF) }’`

if [ $UNIT == "mW" ]; then
MILLI_WATTS=`cat /proc/acpi/battery/BAT$BATTERY/state |
grep "present rate:" | awk ‘{ print $(NF-1) }’`
e cho $[ $MILLI_WATTS / 1000 ].$[ ($MILLI_WATTS % 1000) / 100 ]
MILLI_AMPS=`cat /proc/acpi/battery/BAT$BATTERY/state |
grep "present rate:" | awk ‘{ print $(NF-1) }’`
MILLI_VOLTS=`cat /proc/acpi/battery/BAT$BATTERY/state |
grep "present voltage:" | awk ‘{ print $(NF-1) }’`
echo $[ $POWER / 1000000 ].$[ ($POWER % 1000000) / 100000 ]