Tuesday, 19 March 2019

Cleaning up df output

I use df a lot on ubuntu. Unfortunately with advent of snap devices df output has become increasingly cluttered with various devices mounted by the system that I generally don' have an interest in seeing.

For example:

# /bin/df
Filesystem      1K-blocks       Used Available Use% Mounted on
udev              8121812          0   8121812   0% /dev
tmpfs             1630708       1888   1628820   1% /run
/dev/sda1        30627388   15252072  13796484  53% /
tmpfs             8153528      68012   8085516   1% /dev/shm
tmpfs                5120          4      5116   1% /run/lock
tmpfs             8153528          0   8153528   0% /sys/fs/cgroup
/dev/loop1          93184      93184         0 100% /snap/core/6405
/dev/loop2          93184      93184         0 100% /snap/core/6350
/dev/loop4          35456      35456         0 100% /snap/gtk-common-themes/818
/dev/loop7          35712      35712         0 100% /snap/gtk-common-themes/1122
/dev/sda2        76766240   26915652  45927952  37% /home
/dev/sdb       7814026584 7137072996 674941212  92% /mnt/library
/dev/sdc       3907018584 3436394816 467552000  89% /mnt/archive
tmpfs             1630704         16   1630688   1% /run/user/132
tmpfs             1630704         80   1630624   1% /run/user/1000
/dev/loop8          36224      36224         0 100% /snap/gtk-common-themes/1198
/dev/loop9          93312      93312         0 100% /snap/core/6531
/dev/loop0       48768594   48768594         0 100% /mnt/loop/Archive.TV.01
/dev/loop3       48628258   48628258         0 100% /mnt/loop/Archive.TV.02
/dev/loop5       48845728   48845728         0 100% /mnt/loop/Archive.TV.03

So that you don't have to visually hunt through that junk to see what you need add this to your users .bashrc file:

function df
  /bin/df "$@" | grep -v loop | grep -v tmpfs | grep -v udev

Now your df output just lists the actual mounted drives:

Filesystem      1K-blocks       Used Available Use% Mounted on
/dev/sda1        30627388   15252080  13796476  53% /
/dev/sda2        76766240   26915652  45927952  37% /home
/dev/sdb       7814026584 7137072996 674941212  92% /mnt/library
/dev/sdc       3907018584 3436700752 467246064  89% /mnt/archive
/dev/loop0       48768594   48768594         0 100% /mnt/loop/Archive.TV.01
/dev/loop3       48628258   48628258         0 100% /mnt/loop/Archive.TV.02
/dev/loop5       48845728   48845728         0 100% /mnt/loop/Archive.TV.03

If you want see the full output use the full path /bin/df

autofs: keep devices permanently mounted

I have some ISO images which I use autofs to mount as loop devices.

For reasons that are not important I want them to stay mounted permanently.

I couldn't find any information online on how to do this so I poked around in the related autofs man pages.

I noticed that there is a time out option which is set by default to 600 seconds.

I wondered what would happen if I set that to 0 seconds so I tried it.

So far the devices in question have stayed mounted for 15 minutes

Here's how to do it:

/mnt/loop /etc/auto.loops -t 0

* -fstype=iso9660,loop     :/store/ISO.archives/&.iso

The -t 0 is where we set the time out to 0 (infinite)
In case you are wondering the * at the beginning and the &.iso at the end of auto.loops will mount all of the iso files found in the /store/ISO.archives/ directory.

Monday, 3 September 2018

Steam controller doesn't work in Ubuntu 18.04

After upgrading or fresh install of Ubuntu 18.04 your previously working Steam controller will no longer be detected.

To fix this you must install a new package;

sudo apt install steam-devices

Friday, 22 December 2017

Extract subtitles as SRT from mkv

mkvextract tracks source.mkv track_number:file.srt

You can obtain the track number using mkvtoolnix-gui or mkvinfo

Friday, 6 October 2017

Querying video file metadata with mediainfo

I am working on a script that will query media files (mp4/mkv videos) to obtain metadata that can be subsequently used to rename the file to enforce a naming convention. I use the excellent mediainfo tool (available in the standard repositories) to do this.

mediainfo has a metric tonne of options and functions that you can use for various purposes. In my case I want to know the aspect ratio, vertical height and video codec for the file. This can be done in a single command;

mediainfo --Inform="Video;%DisplayAspectRatio%,%Height%,%Format%"

This works fine and returns something like this;


When I say it works fine I mean it works fine in 99% of cases. The other 1% are made up of files that contain more than one video stream. Sometimes people package a JPEG image inside the container which is designated internally as "Video#2". In such cases the above command will also return values relating to the JPEG image producing something like this;


When this happens my script breaks. The workaround for that is to pipe the results through some unix tools to massage the output;

mediainfo --Inform="Video;%DisplayAspectRatio%,%Height%,%Format%\n" "${_TARGET}" | xargs | awk '{print $1;}'

Things to note in the revised command. There is a carriage return ("\n") at the end of the --Inform parameters which will put the unwanted data on a new line like this;


xargs will remove that line feed and replace it with a space;

1.85,720p,AVC 1.85,720p,JPEG

And finally awk will produce only the first "word" (space delimited) from the result, which produces the desired output.


Now obviously this method assumes that the first video stream in the container is the one we are interested in. I'm struggling to imagine a scenario where this would not be the case so at this point I am OK with that. If I find a file that doesn't work I might have to revise my script, but for now I will stick with this solution.

Saturday, 26 August 2017

Virtualbox remote desktop

I just had a frustrating couple of hours trying to get remote desktop working for a Virtualbox guest.

First, even though the settings screen implies that you merely need to turn remote support on you must also have the virtualbox extension pack installed.

Secondly, if you get "connection refused" or similar errors from the rdesktop client then you are probably using virtualbox 5.0.40

It wasn't until I upgraded virtualbox to 5.1.16 that it just magically started working. grrr