December 19, 2013

Does size matter

Linux var log files are among the things that you should know when working on Linux systems. I don't yet know all their contents, but I can remember a few of them from earlier debugging sessions. I came across these in search of an expression to give me the largest files present on my system.

# du -ha /var | sort -n -r | head -n 10

The result from this command on my system was:

1004K /var/www/user_journeys/manual_cut_out_list.docx
996K /var/lib/dpkg/info/openjdk-7-doc.list
980K /var/lib/dkms/open-vm-tools/2011.12.20/build/vmxnet
976K /var/lib/dkms/open-vm-tools/2011.12.20/build/vmci/common
968K /var/log/auth.log.1
920K /var/lib/dkms/open-vm-tools/2011.12.20/build/vmsync
912K /var/lib/gconf/defaults/%gconf-tree.xml
884K /var/lib/dkms/virtualbox-guest/4.1.12/build/vboxsf
880K /var/lib/dpkg/info/linux-headers-3.5.0-18.list
864K /var/lib/dpkg/info/linux-headers-3.2.0-57.list

December 18, 2013

And I quote:
Thus, for example, read “munger(1)” as “the ‘munger’ program, which will
be documented in section 1 (user tools) of the Unix manual pages, if it’s present on your system”. Section 2 is C system calls, section 3 is C library calls, section 5 is file formats and protocols, section 8 is system administration tools. Other sections vary among Unixes but are not cited in this book. For more, type man 1 man at your Unix shell prompt.
The Art of Unix Programming.

System informaion

When working on Debian based distributions, and most likely other distribution types, you some times need to get system information, here's a bunch commands to get some info:
lsb_release -a
No LSB modules are available.
Distributor ID: LinuxMint
Description: Linux Mint 13 Maya
Release: 13
Codename: maya

uname -a
Linux SorteSlyngel 3.2.0-31-generic-pae #50-Ubuntu SMP Fri Sep 7 16:39:45 UTC 2012 i686 i686 i386 GNU/Linux

apt-cache policy aptitude
aptitude:
  Installed: 0.6.6-1ubuntu1.2
  Candidate: 0.6.6-1ubuntu1.2
  Version table:
 *** 0.6.6-1ubuntu1.2 0
        500 http://archive.ubuntu.com/ubuntu/ precise-updates/main i386 Packages
        100 /var/lib/dpkg/status
     0.6.6-1ubuntu1 0
        500 http://archive.ubuntu.com/ubuntu/ precise/main i386 Packages

apt-cache policy apt
apt:
  Installed: 0.8.16~exp12ubuntu10.16
  Candidate: 0.8.16~exp12ubuntu10.16
  Version table:
 *** 0.8.16~exp12ubuntu10.16 0
        500 http://archive.ubuntu.com/ubuntu/ precise-updates/main i386 Packages
        100 /var/lib/dpkg/status
     0.8.16~exp12ubuntu10.10 0
        500 http://security.ubuntu.com/ubuntu/ precise-security/main i386 Packages
     0.8.16~exp12ubuntu10 0
        500 http://archive.ubuntu.com/ubuntu/ precise/main i386 Packages

apt-cache policy python-apt
python-apt:
  Installed: 0.8.3ubuntu7.1
  Candidate: 0.8.3ubuntu7.1
  Version table:
 *** 0.8.3ubuntu7.1 0
        500 http://archive.ubuntu.com/ubuntu/ precise-updates/main i386 Packages
        100 /var/lib/dpkg/status
     0.8.3ubuntu7 0
        500 http://archive.ubuntu.com/ubuntu/ precise/main i386 Packages

To get the name of a package providing a file:

dpkg -S /bin/ls
A useful trick for finding missing stuff, I had a missing file when upgrading from mint 12 to 13, the above command solved that issue. To get som info on the package found

dpkg -s grub-common
Short post about Debian Administrators Handbook this should be read by all Debian based systems users to understand the aptitude commands.

December 17, 2013

How many hours did you do on this or that project this year?

Yikes, its getting close to the end of the year and I just know somewhere someone is lurking in the shadows to be checking my daily hour registrations. Unfortunately, this year the tool used to post hours in is the *agile* tool redmine.

This tool is of course not compatible with the company hour registrations, so I better create a report by doing some cmdline stuff. Luckily, redmine can export timespend to a csv file this i what I did.

Once the file is ready the following cmdlines can be of assistance for analysing the timesheet data

1. Find All hours spend in 2013 and dump it to a new file
  grep 2013 timelog.csv > time_2013_me.csv

2. Find all projects worked on in 2013
  cut -d ';' -f 1 time_2013_me.csv | sort | uniq

3. Find total amount of reported hours
  cut -d ';' -f 7 time_2013_me.csv | awk '{total = total + $1}END{print total}'

4. Find all hours on a specific project
  grep <project name> time_2013_me.csv | cut -d ';' -f 7 | awk '{total = total + $1}END{print total}'

5. Find alle de andre end specifikt projekt:
  grep -v <project name> time_2013_me.csv | cut -d ';' -f 7 | awk '{total = total + $1}END{print total}'

That's it and that's that.

December 12, 2013

Updating Linux mint ... Ubuntu style!

Every mint distribution, and Ubuntu distribution for that matter, has a distribution name attached. Linux mint12 is called Lisa, mint13 is called Maya etc. All names for Linux mint versions can be found at: old releases and for Ubuntu at: releases
The dist-upgrade trick is to find your current Linux mint release, if you don’t know the name already, it can be found by issuing:
grep mint /etc/apt/sources.list
deb http://packages.linuxmint.com/ lisa main upstream import
The distribution name is preset at the first space after the URL. To get the Ubuntu name replace mint in the grep expression, the list is a bit longer, but the name is still present in the same place. The Ubuntu version is oneiric

You can follow this approach when upgrading all your mint installations, but you should only go one increment at a time.
The best approach for updating is to install the system you’d like to update in a virtual machine, and then apply the update to that system to see what actually happens. Using this approach may seem somewhat overkill, but it is likely to save you a lot of work when trying to fix your broken installation later.

Before you begin you should know that the mint-search-addon package cannot be resolved.
sudo aptitude remove --purge mint-search-addon
If you do not have a log in manager, i.e. mdm you should install this and log out and back in to check that the new manager works flawlessly.
sudo aptitude install mdm
Installing and configuring mdm should ensure that you’re not logging into X using the start X script, as this will most likely break your x log in after the dist upgrade. The Ubuntu x script will be replacing the mint x script, leaving you at an old school log in shell.
sudo aptitude upgrade && sudo aptitude clean
Once the updates has run reboot to ensure that any unknown dependencies are set straight prior to the actual dist upgrade.
sudo reboot
When the system is back in business it’s time to start the actual dist upgrade. We’ll be doing the upgrade Ubuntu style. Issue (Yes I know it a long command):
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup && sudo perl -p -i -e "s/lisa/maya/g" /etc/apt/sources.list && sudo perl -p -i -e "s/oneiric/precise/g" /etc/apt/sources.list && sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove && sudo apt-get autoclean
Notice that the dist upgrade is done using apt-get and not aptitude, this is recommended by Ubuntu, so I’ll use it here but that is the only place.
You should follow the dist upgrade closely, as there will be issues you’ll need to resolve during the dist upgrade. Issues with respect to your current machine’s configuration.
BEWARE: You should not blindly accept changes to your existing /etc/sudoers file! That is the rationale why -y has not been added to the dist-upgrade command. If you are in doubt select the package maintainers version, I usually do this on any update, your old version will be placed by the dpkg program so you’ll always be able to find your old configuration.
With the new packages installed, cross your fingers, hope for the best, and reboot.
sudo reboot
If you get a black screen when you reboot your (virtual) machine, it is most likely due to the graphical support has failed. Try hitting ctrl+f1 to get a old school log in prompt. Log in, then do the upgrade in the terminal until there’s nothing left.
sudo aptitude upgrade
My upgrade stopped at the mint-search-addon package for Firefox, but you have removed this package so it should not cause any problems. If it does anyway run the remove command from above again. 

Once all the upgrades have run you’re ready for starting X to get a feel of what the problems with going graphical may be.  In my case it was a missing setting for the window manager, I had only lightmd installed which attempted to start an Ubuntu session :(
Use the mdm window manager to get things up an running, if you get the missing file /usr/share/mdm/themes/linuxmint/linuxmint.xml dialog it means you’re missing the mint-mdm-themes package so issuing:
sudo aptitude install mdm mint-mdm-themes mint-backgrounds-maya mint-backgrounds-maya-extra
sudo service mdm start
Should bring you to a graphical log in prompt. All you have to do now is resolve the over dependencies that you may have.
My new kernel should not be reconfigured because a link was missing in grub. /usr/share/grub/grub-mkconfig_lib be either a symbolic link or a copy. Setting the symbolic link to /usr/lib/grub/grub-mkconfig_lib can be fixed by:
cd /usr/share/grub/
ln -s grub-mkconfig_lib /usr/lib/grub/grub-mkconfig_lib
then
dpkg --configure -a
Fixed the missing configurable parts for the new kernel dependencies. Now, the kernel image from the old Linux mint12 system must be removed, because it interrupts aptitude and dpkg. The old kernel is removed by:
sudo aptitude remove linux-image-3.0.0-32-generic
Finally, reboot. Wait. Then, once the system is up again, you should be, you’ll need to activate the new repository sources, since dist-upgrade only sets packages to the distribution packages. It does not automatically choose the latest versions of those packages, issue:
sudo aptitude update
sudo aptitude upgrade
Voila, you should be good to go. Some indies may not be hit, some packages may not be installed check the update status from aptitude update there’s a [-xx] counter in the bottom of the terminal, where - means there’s still stuff you could upgrade. Now, if you're up for it, you should try to update to Linux mint 14 (nadia) from this platform ;)


December 10, 2013

Fortune cookies

Fortune cookies, the only computer cookies worth saving.

                                    -- John Dideriksen

And there I was blogging about setting up a apt repository on you website, when suddenly, creating a fortune cookie package struck me. To use the fortunes you'll need fortunes installed, simply issue:

#sudo aptitude install fortunes


Fortune cookies? But how do you get those into your machine, and how do you handle the crumb issues?? Do you install a mouse?

That awkward moment when someone says something so stupid,
all you can do is stare in disbelief.
                                                                                                                                -- INTJ 
 
Fortune cookies are deeply explained right here, too deeply some may say, but I like it. How you bake your own flavored cookies is a completely different question. But, the recipe is extremely simple. Once you have your test file ready, it should look like this, according to the ancient secret recipe.

Fortune cookies, the only computer cookies worth saving.

                                    -- John Dideriksen
%
That awkward moment when someone says something so stupid,
all you can do is stare in disbelief.
 
                                               -- INTJ 
%
I've found him, I got Jesus in the trunk.

                        -- George Carlin
 
Now all you have to do is to install your fortunes using strfile issue:

#sudo cp quotes /usr/share/fortunes
#sudo strfile /usr/share/fortunes/quotes


And then

#fortune quotes

Should hit one of your freshly baked fortune cookies. Putting these freshly baked babies in a jar, in form of a Debian package, is just as easy. Simply create a Debian package following the recipe here.