Useful commands #3: Deleting files with special characters in their filenames

Leave a comment

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

Ever been stuck with a weird file you wanted to delete? You know, those lock files with special characters in their filenames left all over your Samba shares by some Windows applications (for instance)? Today’s post will help you get rid of them in a snap.

First of all, make sure your current directory is the one where your annoying file is located:

cd directory_containing_weird_file

 
Next, list directory’s content using the –inode option:

ls -i

 
You should now see a listing with a number at the beginning of each line. This number corresponds to the unique inode ID of each file and we’ll use it as identifier for the deletion, instead of our bizarre filename. Just do:

find . -inum inode_ID_of_your_file -exec rm -i {} \;

 
The recalcitrant IS wiped out for good this time!

That’s all Folks!


For further reading, you can take a look at ls and rm man pages which detail some other interesting options.

Advertisements

Installing Serviio media streaming server on Ubuntu

Leave a comment

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

Having a home server to centralize and share documents over your network, publish websites or run your own mail server is pretty cool in fact, but today is time to have more fun with your computer rig. Let’s talk about multimedia sharing, streaming and transcoding with the installation of a DLNA server: Serviio.

First of all, head to Serviio website, look for the link to the latest archive for Linux and download it:

wget link_to_latest_serviio_archive

 
Create the /opt/serviio directory and unpack the file to it:

mkdir -p /opt/serviio && tar -C /opt/serviio -xvzf serviio_archive.tar.gz --strip-components=1

 
Then, create a serviio system user:

adduser --system --home /opt/serviio serviio

 
and assign the installation folder ownership to him:

chown serviio:nogroup -R /opt/serviio

 
Create another specific folder which will be used by Serviio to temporarily store the transcoded files (choose the path you prefer but make sure it points to a partition with sufficient free space as multimedia files can be huge):

mkdir /media/md0/.tmp

 
change its access permissions:

chmod 1777 /media/md0/.tmp

 
and then modify the /opt/serviio/bin/serviio.sh script to point to this folder by adding the following parameter at the end of the JAVA_OPTS= line:

-Dserviio.defaultTranscodeFolder=/media/md0/.tmp

 
Now, install all the third party applications needed to have a fully working Serviio: First, install Java if it’s not already installed:

apt-get install default-jre

 
Then, build and install FFmpeg according to the instructions you’ll find in Serviio and FFmpeg Wikis (FFmpeg Wiki contains useful specific instructions dedicated to server/headless machines).

Finally, install dcraw if you need RAW images support:

apt-get install dcraw

 
We’re close to the end now. Let’s just make sure the DLNA server will be launched at startup. To do this, simply create an init script /etc/init/serviio.conf with the following content:

# Serviio - Media Streaming Server
#
# Serviio is a free media server. It allows you to stream your media files
# (music, video or images) to renderer devices (e.g. a TV set, Bluray
# player, games console or mobile phone) on your connected home network.

description "Serviio - Media Streaming Server"

env USER=serviio
env LANG=fr_FR.UTF-8

start on started networking
start on mounted DEVICE=[/UL]*
stop on shutdown

respawn

exec start-stop-daemon --start --make-pidfile --pidfile /var/run/serviio.pid -c $USER --exec /opt/serviio/bin/serviio.sh

(the LANG setting is optional and can be used to define a specific locale)

You can now start the DLNA server (also stop or restart) using the service command:

service serviio start

 
As everything went fine (of course!), you should soon see the server on any UPnP/DLNA device connected to the same subnet. If not, look for suspicious entries in /opt/serviio/log/serviio.log. If you need a more verbose log, modify the org.serviio category as follows in /opt/serviio/config/log4j.xml:

<category name="org.serviio">
   <priority value="DEBUG"/>
</category>

 
and restart Serviio. Now, you should have some clues to help you solve the problem.

One last useful tip: Unfortunately, Serviio lacks a web console in our headless setup. You can find some, proposed by users on Serviio forum, but the easiest solution, for now, is still to install the console on a local Windows client to remotely manage your server settings. Before launching this console, make sure to edit the C:\Program Files\Serviio\bin\ServiioConsole.exe.vmoptions file on the client, add the following line:

-Dserviio.remoteHost=serviio_server_ip_address

 
and everything should be fine.

That’s all Folks!


For further reading, see Serviio very informative wiki and forum.

Useful commands #2: Removing old kernels

Leave a comment

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

In a recent post, I explained how important it is to keep your operating system up to date. If you followed my advices, you may have noticed that Ubuntu’s package manager does not delete any old kernel when upgrading to a new one. It’s on purpose, just to have a known good kernel around in case the upgrade fails. While this is a rather reassuring behavior, you could also want to get rid of these old kernels (to free up some space on your hard disk for example). Let’s see how.

Before doing any cleaning, first write down your current kernel release. You’ll find it by running:

uname -r

 
Next, simulate the old kernels removal:

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get --dry-run remove

 
Here, the –dry-run parameter allows to see the events that would occur during real removal but no change is actually done to the system. Check all the informations displayed on screen to make sure there was no error and verify that your current kernel release was not listed anywhere.

If everything looks fine, you can run the command for real:

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge

 
Old kernels are history now.

That’s all Folks!


For further reading, see the Ubuntu wiki to understand why this removal is not so easy to automate.

Installing a CA certificate on Ubuntu

4 Comments

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

SSL/TLS certificates are everywhere. Whether you connect to your online bank account, setup an FTPS server or sign your applications, you use SSL/TLS certificates. All these certificates have been issued by a certification authority (CA) which your operating system must recognize as a trusted third party. This recognition relies on the CA certificate installation.

In the following example, we’ll install the Class 1 Primary Intermediate Server CA certificate from StartCom, a CA particularly known to supply free domain validated certificates (see StartSSL website for more information). As StartCom Root CA certificate is already installed by default in /usr/share/ca-certificates/mozilla, we’ll use the same path for its intermediate CA certficate.

First, download the certificate:

sudo wget https://www.startssl.com/certs/sub.class1.server.ca.pem -O /usr/share/ca-certificates/mozilla/StartCom_Class_1_Primary_Intermediate_Server_CA.crt

 
Then, add the path to this new certificate (relative to /usr/share/ca-certificates) in /etc/ca-certificates.conf:

mozilla/StartCom_Class_1_Primary_Intermediate_Server_CA.crt

 
Finally, now that everything is in place, just launch:

sudo update-ca-certificates

 
to complete the installation. During this process, /etc/ssl/certs folder’s content will be updated to hold the SSL certificates and ca-certificates.crt, a concatenated single-file list of certificates.

That’s all Folks!


For further reading, refer to Ubuntu manuals.

Useful commands #1: Preventing the update of a package

Leave a comment

Successfully tested on Ubuntu Server 12.04 LTS 64-bit

Doing frequent updates of your favorite OS and programs is always recommended. Not only does it allow you to take advantage of new features but it also minimizes the security risks by correcting the possible flaws spotted since the installation or the previous update.

In Ubuntu, software updates can be either automatic (see Automatic Updates in the official documentation for details) or… manual. If you choose to go the manual way, you’ll have to make sure to do the updates by yourself on a regular basis (Ubuntu’s welcome screen advises you of updates availability) using two commands:

sudo apt-get update

 
first, to re-synchronize the package index files from their sources (the repositories are listed in /etc/apt/sources.list), followed by:

sudo apt-get upgrade

 
to finally install the newest versions of all packages currently installed on the system.

This full update in one shot is very handy of course, but what to do if you don’t want to update a specific package? For instance, let say you patched and rebuilt a program for whatever reason and you don’t want it to be replaced by the new latest official version. What to do? This is where today’s useful command comes in:

sudo apt-mark hold package_name

 
Now, this package will never be updated automatically as well as manually as long as it is on “hold” status. To display this status, you can use:

dpkg --get-selections | grep "package_name"

 
Finally, the day you decide to allow the upgrade to the latest version available in the official repository, just type:

sudo apt-mark unhold package_name

 
to put the package back on “install” status.

That’s all Folks!


For further reading, take a look at Package Management in Ubuntu’s official documentation.

Ubuntu Server system administration made easier: Webmin

Leave a comment

Successfully tested on Ubuntu Server 10.04 LTS 64-bit

Tired of being a command-line master? You would like to do Ubuntu Server administration tasks using some kind of GUI? DO NOT install Ubuntu’s desktop environment. Install Webmin instead.

The easiest way to install Webmin on Ubuntu is by using the official Webmin APT repository. First, create a new /etc/apt/sources.list.d/webmin.list file containing the following lines:

## Webmin repository
deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib

 
Next, get the repository GPG key

wget http://www.webmin.com/jcameron-key.asc

 
and add it to your trusted keys list:

apt-key add jcameron-key.asc

 
Finally, resynchronize the list of available packages

apt-get update

 
and install Webmin:

apt-get install webmin

 
Now, you should be able to login to Webmin at https://webmin_server_hostname:10000 using any existing sudoer account and discover the many possibilities of this wonderful tool.

That’s all Folks!


For further reading, see Webmin website.